phpcop 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +23 -0
- data/Rakefile +2 -0
- data/bin/phpcop +16 -0
- data/config/default.yml +17 -0
- data/lib/phpcop/cli.rb +51 -0
- data/lib/phpcop/configloader.rb +23 -0
- data/lib/phpcop/configstore.rb +7 -0
- data/lib/phpcop/cop/files/phptags.rb +61 -0
- data/lib/phpcop/runner.rb +5 -0
- data/lib/phpcop/version.rb +4 -0
- data/lib/phpcop.rb +8 -0
- data/phpcop.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 743c6a613d5bf326b3021c4945eced461400280c
|
4
|
+
data.tar.gz: fc484f73e15bf03bc577e2f8ca05370b1be2e832
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 08044f4b9cd57894a303c7e79695f401365b0ae80836bdcfc2ffe34e422242026aa869ece3776da04edb2f5f0e5c2e49e7929b3010e0e20ebfff65606ecdee0c
|
7
|
+
data.tar.gz: 1cc847c3f46e232c3bd439d88ed2d3af62f2e21637e5cd4c81141feff6cd1f26d0a4bce73db80d203fb7e6fbbade9dbdce64bd1329b9792c3de00405680f0309
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Vaillant Jeremy
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Phpcop
|
2
|
+
|
3
|
+
Tools for detect error (PSRs)[http://www.php-fig.org/].
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'phpcop'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install phpcop
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Go to project and execute command `phpcop`.
|
data/Rakefile
ADDED
data/bin/phpcop
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'phpcop'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
cli = PhpCop::CLI.new
|
7
|
+
result = 0
|
8
|
+
|
9
|
+
puts format('Scan project : %s', Dir.pwd)
|
10
|
+
|
11
|
+
time = Benchmark.realtime do
|
12
|
+
result = cli.run
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "Finished in #{time} seconds"
|
16
|
+
exit 0
|
data/config/default.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Configuration for application
|
2
|
+
php:
|
3
|
+
# Precise PHP version
|
4
|
+
version: 7
|
5
|
+
# Precise convention used
|
6
|
+
rules:
|
7
|
+
- PSR-2
|
8
|
+
# Precise framework used
|
9
|
+
framework: zf-2
|
10
|
+
|
11
|
+
AllCops:
|
12
|
+
# Exclude:
|
13
|
+
# - '**/'
|
14
|
+
phpTags:
|
15
|
+
enabled: true
|
16
|
+
description: 'PHP Tags'
|
17
|
+
see: 'http://www.php-fig.org/psr/psr-1/#2-1-php-tags'
|
data/lib/phpcop/cli.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module PhpCop
|
2
|
+
# The CLI is a class responsible of handling all the command line interface
|
3
|
+
# logic
|
4
|
+
class CLI
|
5
|
+
EXT = %w(.php .phtml .php.dist).freeze
|
6
|
+
EXCLUDE_FOLDER = %w(. .. .git .gitignore vendor).freeze
|
7
|
+
|
8
|
+
attr_reader :options, :config_store, :count_files
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@options = {}
|
12
|
+
@config_store = ConfigStore.new
|
13
|
+
@count_files = 0
|
14
|
+
@count_errors = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
# Run all files
|
18
|
+
def run(_args = ARGV)
|
19
|
+
Dir.foreach(Dir.pwd) do |file|
|
20
|
+
run_folder(file, Dir.pwd)
|
21
|
+
end
|
22
|
+
|
23
|
+
puts format('%s fichier traité. %s erreurs.', @count_files, @count_errors)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def foreach_folder(path)
|
29
|
+
Dir.foreach(path) do |file|
|
30
|
+
run_folder(file, path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_folder(file, path)
|
35
|
+
unless EXCLUDE_FOLDER.include?(file)
|
36
|
+
f = path + '/' + file
|
37
|
+
if File.directory?(f)
|
38
|
+
foreach_folder(f)
|
39
|
+
elsif EXT.include?(File.extname(file))
|
40
|
+
execute_tests_in_file(file, path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def execute_tests_in_file(file, path)
|
46
|
+
@count_files += 1
|
47
|
+
test = PhpCop::Cop::Files::PhpTags.new(format('%s/%s', path, file))
|
48
|
+
@count_errors += test.errors
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Phpcop
|
4
|
+
# This class load a files configuration to gem. So config file default and
|
5
|
+
# customize config file in project scan
|
6
|
+
class ConfigLoader
|
7
|
+
# Config file in gem
|
8
|
+
DEFAULT_CONF = 'config/default.yml'.freeze
|
9
|
+
# Config file in project PHP
|
10
|
+
CUSTOMIZE_CONF = '.phpcop.yml'.freeze
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
load_configuration(DEFAULT_CONF)
|
14
|
+
load_configuration(CUSTOMIZE_CONF)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def load_configuration(file)
|
20
|
+
File.exist?(file) ? YAML.load(file) : false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module PhpCop
|
2
|
+
module Cop
|
3
|
+
module Files
|
4
|
+
# This class test file php use correctly tags PHP '<?php ?>' or '<?= ?>'
|
5
|
+
class PhpTags
|
6
|
+
MSG_ALERT = '%s, dont use correctly PHP Tags.'.freeze
|
7
|
+
TAG_OPEN = ['\<\?php', '\<\?='].freeze
|
8
|
+
TAG_CLOSE = ['\?\>'].freeze
|
9
|
+
|
10
|
+
attr_reader :errors
|
11
|
+
|
12
|
+
def initialize(file)
|
13
|
+
@count_open = 0
|
14
|
+
@count_close = 0
|
15
|
+
@errors = 0
|
16
|
+
|
17
|
+
# Open file and parse
|
18
|
+
f = File.open(file, 'r')
|
19
|
+
while (line = f.gets)
|
20
|
+
parse_line(line)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Test counters if there are equal
|
24
|
+
test_counters(file)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_line(line)
|
30
|
+
# Parse file and search tags exists
|
31
|
+
parse_and_search_open_tag(line)
|
32
|
+
# If file contains tag <?php or <?= search close tags
|
33
|
+
parse_and_search_close_tag(line)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Parse file and search tags
|
37
|
+
def parse_and_search_open_tag(line)
|
38
|
+
TAG_OPEN.each do |rule|
|
39
|
+
@count_open += 1 if Regexp.new(rule).match line
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_and_search_close_tag(line)
|
44
|
+
TAG_CLOSE.each do |rule|
|
45
|
+
@count_close += 1 if Regexp.new(rule).match line
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_counters(file)
|
50
|
+
return_an_error(file) unless @count_open == @count_close
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return a text error with file name
|
54
|
+
def return_an_error(file)
|
55
|
+
puts format(MSG_ALERT, file)
|
56
|
+
@errors += 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/phpcop.rb
ADDED
data/phpcop.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'phpcop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'phpcop'
|
8
|
+
spec.version = Phpcop::VERSION
|
9
|
+
spec.authors = ['Jeremy VAILLANT']
|
10
|
+
spec.email = ['vaillant.jeremy@dev-crea.com']
|
11
|
+
|
12
|
+
spec.summary = 'Parse PHP code and analyser.'
|
13
|
+
spec.description = 'Parser php files and gives non-respected guidelines.'
|
14
|
+
spec.homepage = 'https://github.com/Dev-Crea/phpcop'
|
15
|
+
|
16
|
+
r = %r{^(test|spec|features)/}
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(r) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'overcommit', '~> 0.32.0'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.38.0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phpcop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy VAILLANT
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-19 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: overcommit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.32.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.32.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.38.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.38.0
|
69
|
+
description: Parser php files and gives non-respected guidelines.
|
70
|
+
email:
|
71
|
+
- vaillant.jeremy@dev-crea.com
|
72
|
+
executables:
|
73
|
+
- phpcop
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/phpcop
|
83
|
+
- config/default.yml
|
84
|
+
- lib/phpcop.rb
|
85
|
+
- lib/phpcop/cli.rb
|
86
|
+
- lib/phpcop/configloader.rb
|
87
|
+
- lib/phpcop/configstore.rb
|
88
|
+
- lib/phpcop/cop/files/phptags.rb
|
89
|
+
- lib/phpcop/runner.rb
|
90
|
+
- lib/phpcop/version.rb
|
91
|
+
- phpcop.gemspec
|
92
|
+
homepage: https://github.com/Dev-Crea/phpcop
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Parse PHP code and analyser.
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|