pronto-phpmd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +22 -0
- data/lib/pronto/phpmd.rb +61 -0
- data/lib/pronto/phpmd/version.rb +5 -0
- data/pronto-phpmd.gemspec +23 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f8d8b8d417e7ec492d1d246ea116ffa5a8c00f9
|
4
|
+
data.tar.gz: 1e18d6f8e71c54a38f5162ff47c32842404ca25a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28574b4761d9c2232c306c47aa2823ff3cfa57a6cdd8b6fe31b69177137f216ff173b12fd90da71c734eea1a7e3c94056f0673b65b8afa85b217a13dd2b467fa
|
7
|
+
data.tar.gz: f01e39888941379f5f351cbb09324ed04401d1479220cfa731eb6a81797f4c0e9678e1307d24b94608f7fe0a7347074fdf6ec9bb523d642a479de00ae7f3249a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Eligijus Vitkauskas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Pronto runner for PHPMD
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/EllisV/pronto-phpmd.svg?branch=master)](https://travis-ci.org/EllisV/pronto-phpmd)
|
4
|
+
|
5
|
+
Pronto runner for [PHPMD](https://github.com/phpmd/phpmd).
|
6
|
+
[What is Pronto?](https://github.com/mmozuras/pronto)
|
7
|
+
|
8
|
+
|
9
|
+
Configuration
|
10
|
+
-------------
|
11
|
+
|
12
|
+
Configuration is available via following environment variables
|
13
|
+
|
14
|
+
| Name | Default |
|
15
|
+
|---------------------------|-----------------------------------------------------------|
|
16
|
+
| `PRONTO_PHPMD_EXECUTABLE` | phpmd |
|
17
|
+
| `PRONTO_PHPMD_RULESET` | cleancode,codesize,controversial,design,naming,unusedcode |
|
18
|
+
|
19
|
+
Copyright
|
20
|
+
---------
|
21
|
+
|
22
|
+
Copyright (c) 2016 Eligijus Vitkauskas. See [LICENSE](LICENSE) for further details.
|
data/lib/pronto/phpmd.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pronto'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
module Pronto
|
6
|
+
class Phpmd < Runner
|
7
|
+
def initialize(patches, commit = nil)
|
8
|
+
super
|
9
|
+
|
10
|
+
@executable = ENV['PRONTO_PHPMD_EXECUTABLE'] || 'phpmd'
|
11
|
+
@ruleset = ENV['PRONTO_PHPMD_RULESET'] || 'cleancode,codesize,controversial,design,naming,unusedcode'
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
return [] unless @patches
|
16
|
+
|
17
|
+
@patches.select { |patch| valid_patch?(patch) }
|
18
|
+
.map { |patch| inspect(patch) }
|
19
|
+
.flatten.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_patch?(patch)
|
23
|
+
patch.additions > 0 && php_file?(patch.new_file_full_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect(patch)
|
27
|
+
path = patch.new_file_full_path.to_s
|
28
|
+
run_phpmd(path).map do |offence|
|
29
|
+
patch.added_lines.select { |line| line.new_lineno == offence[:line] }
|
30
|
+
.map { |line| new_message(offence, line) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_phpmd(path)
|
35
|
+
escaped_executable = Shellwords.escape(@executable)
|
36
|
+
escaped_path = Shellwords.escape(path)
|
37
|
+
escaped_ruleset = Shellwords.escape(@ruleset)
|
38
|
+
|
39
|
+
xml = `#{escaped_executable} #{escaped_path} xml #{escaped_ruleset}`
|
40
|
+
doc = REXML::Document.new(xml)
|
41
|
+
|
42
|
+
doc.elements.collect('pmd/file/violation') do |el|
|
43
|
+
line = el.attributes['beginline'].to_i
|
44
|
+
next unless line > 0
|
45
|
+
|
46
|
+
{ line: line, msg: el.first.to_s.strip }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def new_message(offence, line)
|
51
|
+
path = line.patch.delta.new_file[:path]
|
52
|
+
level = :warning
|
53
|
+
|
54
|
+
Message.new(path, line, level, offence[:msg], nil, self.class)
|
55
|
+
end
|
56
|
+
|
57
|
+
def php_file?(path)
|
58
|
+
File.extname(path) == '.php'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pronto/phpmd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pronto-phpmd'
|
8
|
+
spec.version = Pronto::PhpmdVersion::VERSION
|
9
|
+
spec.authors = ['Eligijus Vitkauskas']
|
10
|
+
spec.email = ['eligijusvitkauskas@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Pronto runner for PHPMD'
|
13
|
+
spec.homepage = 'https://github.com/EllisV/pronto-phpmd'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = Dir.glob('lib/**/*.rb') + ['pronto-phpmd.gemspec', 'LICENSE', 'README.md']
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency('pronto', '~> 0.7.0')
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-phpmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eligijus Vitkauskas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- eligijusvitkauskas@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- lib/pronto/phpmd.rb
|
79
|
+
- lib/pronto/phpmd/version.rb
|
80
|
+
- pronto-phpmd.gemspec
|
81
|
+
homepage: https://github.com/EllisV/pronto-phpmd
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Pronto runner for PHPMD
|
105
|
+
test_files: []
|