phpcs 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 546837ec1fca4e9addd0f89f9cd14f1547014fcc
4
+ data.tar.gz: 7e0e3b4d4dca2c818699a9dc9486ddea3dff2b86
5
+ SHA512:
6
+ metadata.gz: 1277e55e91dedf79d29109fc151c8e30cdbc45afbd4e769a5d3e3511bd9242a9568f84d19780b1fd9f0d3fafa9b35f242cda9a3f76c7ebae5ee653b1e3f165ca
7
+ data.tar.gz: 1981bc2df470826dd38ede08da22b3b8d4e35de22afc7d8d09ae78376871f5688a467b710a621620d168eba821fb34046fdb92ac3f5bfecc54e3a0362d7818c3
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,17 @@
1
+ language: php
2
+
3
+ php:
4
+ - 5.4
5
+ - 5.5
6
+
7
+ before_install:
8
+ - pyrus install pear/PHP_CodeSniffer
9
+ - phpenv rehash
10
+
11
+ script:
12
+ - gem update bundler
13
+ - bundle install
14
+ - bundle exec rake
15
+
16
+ notifications:
17
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Craftsmen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ [![Build Status](https://magnum.travis-ci.com/craftsmen/phpcs-rb.svg?token=CdVCrysG3xdFiGU8XWq1&branch=0.0.1)](https://magnum.travis-ci.com/craftsmen/phpcs-rb)
2
+
3
+ # Phpcs
4
+
5
+ Phpcs is a ruby wrapper for Php_CodeSniffer.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'phpcs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install phpcs
22
+
23
+ ## Usage
24
+
25
+ Take a look to `test/phpcs_test.rb` to understand how to use it.
26
+
27
+ You can choose one of the follwing coding standards: `PEAR, PHPCS, PSR1, PSR2 (default), Squiz, Zend`
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/foo/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.pattern = 'test/**/*_test.rb'
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,52 @@
1
+ require 'tempfile'
2
+ require 'base64'
3
+ require 'open3'
4
+ require 'json'
5
+
6
+ module Phpcs
7
+ class Match < Struct.new(:line, :comment)
8
+ end
9
+
10
+ class Phpcs
11
+ STANDARDS = [
12
+ 'PEAR',
13
+ 'PHPCS',
14
+ 'PSR1',
15
+ 'PSR2',
16
+ 'Squiz',
17
+ 'Zend'
18
+ ]
19
+
20
+ def initialize(standard = nil)
21
+ @standard = (STANDARDS.include? standard) ? standard : 'PSR2'
22
+ end
23
+
24
+ def lint(content)
25
+ code = Base64.encode64(content).strip[0..16]
26
+ file = Tempfile.new(code)
27
+ file.write(content)
28
+ file.close
29
+
30
+ stdin, stdout, stderr, wait_thr = Open3.popen3('phpcs', file.path, "--standard=#{@standard}", '--report=json')
31
+
32
+ out = JSON.load(stdout.read)
33
+
34
+ if out['totals']['errors'] > 0
35
+ parse_matches(out)
36
+ else
37
+ []
38
+ end
39
+ end
40
+
41
+ def parse_matches(body)
42
+ path = body['files'].keys.first
43
+ errors = body['files'][path]
44
+ matches = []
45
+
46
+ errors['messages'].each do |error|
47
+ matches << Match.new(error['line'], error['message'])
48
+ end
49
+ matches
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Phpcs
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phpcs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'phpcs'
8
+ spec.version = Phpcs::VERSION
9
+ spec.authors = ['Kevin Chavanne']
10
+ spec.email = ['kevin@craftsmen.io']
11
+ spec.summary = %q{Ruby wrapper for phpcs}
12
+ spec.description = %q{Ruby wrapper for phpcs}
13
+ spec.homepage = 'https://github.com/craftsmen/phpcs-rb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'minitest', '~> 5.4'
24
+ spec.add_dependency 'json', '~> 1.8'
25
+ end
@@ -0,0 +1,11 @@
1
+ <?php
2
+
3
+ class Foo {
4
+
5
+ public function bar() {
6
+ return 'hello';
7
+ }
8
+
9
+ }
10
+
11
+ ?>
@@ -0,0 +1,84 @@
1
+ require 'minitest/autorun'
2
+ require 'phpcs'
3
+ require 'minitest/pride'
4
+
5
+ class PhpcsTest < Minitest::Test
6
+ def test_defaut_standard
7
+ file = File.open('test/fixtures/foo.php')
8
+ phpcs = Phpcs::Phpcs.new
9
+ results = phpcs.lint(file.read)
10
+
11
+ assert_equal results[0].line, 3
12
+ assert_equal results[0].comment, 'Each class must be in a namespace of at least one level (a top-level vendor name)'
13
+ assert_equal results[1].line, 3
14
+ assert_equal results[1].comment, 'Opening brace of a class must be on the line after the definition'
15
+ assert_equal results[2].line, 5
16
+ assert_equal results[2].comment, 'Spaces must be used to indent lines; tabs are not allowed'
17
+ assert_equal results[3].line, 5
18
+ assert_equal results[3].comment, 'Line indented incorrectly; expected at least 4 spaces, found 1'
19
+ assert_equal results[4].line, 5
20
+ assert_equal results[4].comment, 'Line indented incorrectly; expected 4 spaces, found 1'
21
+ assert_equal results[5].line, 5
22
+ assert_equal results[5].comment, 'Opening brace should be on a new line'
23
+ assert_equal results[6].line, 6
24
+ assert_equal results[6].comment, 'Spaces must be used to indent lines; tabs are not allowed'
25
+ assert_equal results[7].line, 6
26
+ assert_equal results[7].comment, 'Line indented incorrectly; expected at least 8 spaces, found 3'
27
+ assert_equal results[8].line, 7
28
+ assert_equal results[8].comment, 'Spaces must be used to indent lines; tabs are not allowed'
29
+ assert_equal results[9].line, 9
30
+ assert_equal results[9].comment, 'The closing brace for the class must go on the next line after the body'
31
+ assert_equal results[10].line, 11
32
+ assert_equal results[10].comment, 'A closing tag is not permitted at the end of a PHP file'
33
+ end
34
+
35
+ def test_pear_standard
36
+ file = File.open('test/fixtures/foo.php')
37
+ phpcs = Phpcs::Phpcs.new('PEAR')
38
+ results = phpcs.lint(file.read)
39
+
40
+ assert_equal results[0].line, 2
41
+ assert_equal results[0].comment, 'Missing file doc comment'
42
+ assert_equal results[1].line, 3
43
+ assert_equal results[1].comment, 'Missing class doc comment'
44
+ assert_equal results[2].line, 3
45
+ assert_equal results[2].comment, 'Opening brace of a class must be on the line after the definition'
46
+ assert_equal results[3].line, 5
47
+ assert_equal results[3].comment, 'Spaces must be used to indent lines; tabs are not allowed'
48
+ assert_equal results[4].line, 5
49
+ assert_equal results[4].comment, 'Line indented incorrectly; expected at least 4 spaces, found 1'
50
+ assert_equal results[5].line, 5
51
+ assert_equal results[5].comment, 'Missing function doc comment'
52
+ assert_equal results[6].line, 5
53
+ assert_equal results[6].comment, 'Line indented incorrectly; expected 4 spaces, found 1'
54
+ assert_equal results[7].line, 5
55
+ assert_equal results[7].comment, 'Opening brace should be on a new line'
56
+ assert_equal results[8].line, 6
57
+ assert_equal results[8].comment, 'Spaces must be used to indent lines; tabs are not allowed'
58
+ assert_equal results[9].line, 6
59
+ assert_equal results[9].comment, 'Line indented incorrectly; expected at least 8 spaces, found 3'
60
+ assert_equal results[10].line, 7
61
+ assert_equal results[10].comment, 'Spaces must be used to indent lines; tabs are not allowed'
62
+ end
63
+
64
+ def test_zend_standard
65
+ file = File.open('test/fixtures/foo.php')
66
+ phpcs = Phpcs::Phpcs.new('Zend')
67
+ results = phpcs.lint(file.read)
68
+
69
+ assert_equal results[0].line, 3
70
+ assert_equal results[0].comment, 'Opening brace of a class must be on the line after the definition'
71
+ assert_equal results[1].line, 5
72
+ assert_equal results[1].comment, 'Spaces must be used to indent lines; tabs are not allowed'
73
+ assert_equal results[2].line, 5
74
+ assert_equal results[2].comment, 'Opening brace should be on a new line'
75
+ assert_equal results[3].line, 6
76
+ assert_equal results[3].comment, 'Spaces must be used to indent lines; tabs are not allowed'
77
+ assert_equal results[4].line, 7
78
+ assert_equal results[4].comment, 'Spaces must be used to indent lines; tabs are not allowed'
79
+ assert_equal results[5].line, 11
80
+ assert_equal results[5].comment, 'A closing tag is not permitted at the end of a PHP file'
81
+ end
82
+
83
+
84
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phpcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Chavanne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: Ruby wrapper for phpcs
70
+ email:
71
+ - kevin@craftsmen.io
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/phpcs.rb
83
+ - lib/phpcs/version.rb
84
+ - phpcs.gemspec
85
+ - test/fixtures/foo.php
86
+ - test/phpcs_test.rb
87
+ homepage: https://github.com/craftsmen/phpcs-rb
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby wrapper for phpcs
111
+ test_files:
112
+ - test/fixtures/foo.php
113
+ - test/phpcs_test.rb