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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ef9b83034da7e194fb6d2ed9f9d98ebd1c4b2ba
4
- data.tar.gz: 2707957b3b3b80b58e03babe2acf2eec19808805
3
+ metadata.gz: 2e3d4d38c484bea2b33984349716824b4d6539d4
4
+ data.tar.gz: ded7b85d0f430d9834361f8e959c89165ada3f72
5
5
  SHA512:
6
- metadata.gz: 84d475a58cecdcf05d00ea15c36241af52ca3a4704ec8dc3e52947ce15a7e07d86af26b5d43865456bd0f86340609ebd7d842f3005aeb59d294c8c23ee22d06d
7
- data.tar.gz: 0833da19a707ac122d95aedd14fcfd86642db1a5a66a5a3e23569e64c7593619d5b21aa6bb9c1849877e2b111dc226e49a1eff77772cf8d1eca5b369e3bbc860
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
- http://www.php-fig.org/psr/psr-1/#4-3-methods
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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Phpcop
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.3'
6
6
  end
data/lib/phpcop.rb CHANGED
@@ -13,3 +13,4 @@ require 'phpcop/cop/cop.rb'
13
13
  require 'phpcop/cop/files/phptags.rb'
14
14
  require 'phpcop/cop/files/phpencoding.rb'
15
15
  require 'phpcop/cop/ccpm/methods.rb'
16
+ require 'phpcop/cop/ccpm/constants.rb'
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.1
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-21 00:00:00.000000000 Z
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