phpcop 0.3.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +7 -1
- data/lib/phpcop/cop/ccpm/constants.rb +43 -0
- data/lib/phpcop/runner.rb +7 -0
- data/lib/phpcop/version.rb +1 -1
- data/lib/phpcop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e3d4d38c484bea2b33984349716824b4d6539d4
|
4
|
+
data.tar.gz: ded7b85d0f430d9834361f8e959c89165ada3f72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce4756471d9fd32b1e5d002dd6f211700131bf047c6e88b8e248466a2ec38eeaf91401940c2a7441a776f670c86023c7d9b7edefe197bb75b5ca0b7fb49e9d1a
|
7
|
+
data.tar.gz: 562fad8df27cf6d9236f7443586c15c46fb26ebe8e4518a612e63798f76a616622dd2158de0d91aea519aa0f726e53eb69ae52845749a7ac5e943cbb09bc35f2
|
data/config/default.yml
CHANGED
@@ -25,5 +25,11 @@ AllCops:
|
|
25
25
|
ccpm/methods:
|
26
26
|
enabled: true
|
27
27
|
description: >
|
28
|
-
|
28
|
+
Method names MUST be declared in camelCase().
|
29
29
|
see: 'http://www.php-fig.org/psr/psr-1/#4-3-methods'
|
30
|
+
ccpm/constants:
|
31
|
+
enabled: true
|
32
|
+
description: >
|
33
|
+
Class constants MUST be declared in all upper case with underscore
|
34
|
+
separators.
|
35
|
+
see: 'http://www.php-fig.org/psr/psr-1/#4-1-constants'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module PhpCop
|
5
|
+
module Cop
|
6
|
+
# Acronym to Class Constants, Properties and Methods
|
7
|
+
module CCPM
|
8
|
+
# Test constant in php class
|
9
|
+
class Constants < Cop
|
10
|
+
MSG_ALERT_DESCRIB = 'Class constants MUST be declared in all upper '\
|
11
|
+
'case with underscore separators.'
|
12
|
+
|
13
|
+
def initialize(file, line, line_number)
|
14
|
+
super(file, line.to_s, line_number)
|
15
|
+
test_line
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def test_line
|
21
|
+
test_constant_valid if @line.include?(' const ')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_constant_valid
|
25
|
+
name = @line.slice!(/const.*=/)
|
26
|
+
unless name.nil?
|
27
|
+
name = name.gsub('const ', '').gsub(' =', '')
|
28
|
+
n_constant = name.upcase
|
29
|
+
return_an_error(@file, @line_number, 0) unless n_constant.eql? name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def return_an_error(file, line, column)
|
34
|
+
@errors += 1
|
35
|
+
line += 1
|
36
|
+
puts format(MSG_ALERT_FILE, file, line, column)
|
37
|
+
puts MSG_ALERT_DESCRIB
|
38
|
+
puts ''
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/phpcop/runner.rb
CHANGED
@@ -69,6 +69,8 @@ module PhpCop
|
|
69
69
|
test_file_php_encoding(file, line, line_number)
|
70
70
|
when 'methods'
|
71
71
|
test_ccpm_methods(file, line, line_number)
|
72
|
+
when 'constants'
|
73
|
+
test_ccpm_constants(file, line, line_number)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -85,5 +87,10 @@ module PhpCop
|
|
85
87
|
test = PhpCop::Cop::CCPM::Methods.new(file, line, line_number)
|
86
88
|
@count_errors += test.errors
|
87
89
|
end
|
90
|
+
|
91
|
+
def test_ccpm_constants(file, line, line_number)
|
92
|
+
test = PhpCop::Cop::CCPM::Constants.new(file, line, line_number)
|
93
|
+
@count_errors += test.errors
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
data/lib/phpcop/version.rb
CHANGED
data/lib/phpcop.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phpcop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy VAILLANT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/phpcop/cli.rb
|
103
103
|
- lib/phpcop/configloader.rb
|
104
104
|
- lib/phpcop/configstore.rb
|
105
|
+
- lib/phpcop/cop/ccpm/constants.rb
|
105
106
|
- lib/phpcop/cop/ccpm/methods.rb
|
106
107
|
- lib/phpcop/cop/cop.rb
|
107
108
|
- lib/phpcop/cop/files/phpencoding.rb
|