phpcop 0.5.4 → 0.5.6

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: 21740e8e63f9fa63630ee1580dbe6cf00f586ff3
4
- data.tar.gz: d6848133f0c897e3345092a37581af74f167eca4
3
+ metadata.gz: f95f331088725a8f4f3aa1d2f2818e186bf3f201
4
+ data.tar.gz: c4c67475c387c22635d5425308d408559377206e
5
5
  SHA512:
6
- metadata.gz: 03f7d41acbff8f04b9fa195984f53f25b8e95db12c46a4b0f61d2f2faf05a96f7205e8680b33f951cc707e5dc25e0c9b2c59d5be82ea4333ca970044531372c5
7
- data.tar.gz: 9fd4a1bdbb2d10655fb82f15c10e52e179ba00137763b2ef872c512945cda728b6378db3c948c081719414083224a7a6406ab110fbd110ef13e90661b61fd5d8
6
+ metadata.gz: fa3ec6b704fee5c9a31553a974cb4332e46fce8f7946c20dfd8775eaf71f1915df69698843548c086a5e01d2b431671d29de72391209249701d6df99cad16317
7
+ data.tar.gz: e09c7f1199129f2b53623a171f22e5b52a62b48badfacbc2678747b67bc67436406c4b8e382d4a6e94521bfd29d536eb4d6484805586ee3d4d57112d0079515c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Phpcop
2
2
 
3
- Tools for detect error (PSRs)[http://www.php-fig.org/].
3
+ Tools for detect error [PSRs](http://www.php-fig.org/).
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,8 +10,8 @@ module PhpCop
10
10
  MSG_ALERT_DESCRIB = 'Class constants MUST be declared in all upper '\
11
11
  'case with underscore separators.'
12
12
 
13
- def initialize(file, line, line_number)
14
- super(file, line.to_s, line_number)
13
+ def initialize(file, path, line, line_number)
14
+ super(file, path, line, line_number)
15
15
  test_line
16
16
  end
17
17
 
@@ -26,7 +26,7 @@ module PhpCop
26
26
  unless name.nil?
27
27
  name = name.gsub('const ', '').gsub(' =', '')
28
28
  n_constant = name.upcase
29
- return_an_error(@file, @line_number, 0) unless n_constant.eql? name
29
+ return_an_error(MSG_ALERT_DESCRIB) unless n_constant.eql? name
30
30
  end
31
31
  end
32
32
  end
@@ -11,8 +11,8 @@ module PhpCop
11
11
  class Methods < Cop
12
12
  MSG_ALERT_DESCRIB = 'Name method is not in camelCase().'
13
13
 
14
- def initialize(file, line, line_number)
15
- super(file, line.to_s, line_number)
14
+ def initialize(file, path, line, line_number)
15
+ super(file, path, line, line_number)
16
16
  test_line
17
17
  end
18
18
 
@@ -27,7 +27,7 @@ module PhpCop
27
27
  name = name.gsub(/\(.*/, '')
28
28
  unless name.include?('__')
29
29
  name_camel = name.camelize(:lower)
30
- return_an_error(@file, @line_number, 0) unless name_camel.eql? name
30
+ return_an_error(MSG_ALERT_DESCRIB) unless name_camel.eql? name
31
31
  end
32
32
  end
33
33
  end
@@ -7,25 +7,27 @@ module PhpCop
7
7
  class Cop
8
8
  attr_reader :errors
9
9
  # Display an error 'fichier.ext:line:column'
10
- MSG_ALERT_FILE = '%s:%s:%s'
11
- MSG_ALERT_DESCRIB = ''
10
+ MSG_ALERT_FILE = '%s/%s:%s:%s'
12
11
 
13
- def initialize(file, line, line_number)
12
+ def initialize(file, path, line, line_number)
14
13
  @count_open = 0
15
14
  @count_close = 0
16
15
  @errors = 0
16
+ @path = path
17
17
  @file = file
18
- @line = line
18
+ @line = line.to_s
19
19
  @line_number = line_number
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def return_an_error(file, line, column)
24
+ def return_an_error(message_alert_describ)
25
25
  @errors += 1
26
- line += 1
27
- puts format(MSG_ALERT_FILE, file, line, column)
28
- puts MSG_ALERT_DESCRIB
26
+ puts format('line number : %s', @line_number)
27
+ @line_number += 1
28
+ @column = 0
29
+ puts format(MSG_ALERT_FILE, @path, @file, @line_number, @column)
30
+ puts message_alert_describ
29
31
  puts ''
30
32
  end
31
33
  end
@@ -8,8 +8,8 @@ module PhpCop
8
8
  class PhpEncoding < Cop
9
9
  MSG_ALERT_DESCRIB = 'Is not encoding in UTF-8 without BOM.'
10
10
 
11
- def initialize(file, line, line_number)
12
- super(file, line.to_s, line_number)
11
+ def initialize(file, path, line, line_number)
12
+ super(file, path, line.to_s, line_number)
13
13
  test_line
14
14
  end
15
15
 
@@ -18,9 +18,7 @@ module PhpCop
18
18
  # Parse line and test if line is correctly enconding
19
19
  def test_line
20
20
  line_encoding = @line
21
- unless line_encoding.ascii_only?
22
- return_an_error(@file, @line_number, 0)
23
- end
21
+ return_an_error(MSG_ALERT_DESCRIB) unless line_encoding.ascii_only?
24
22
  end
25
23
 
26
24
  # TODO : Return position column to char non ASCII
@@ -12,15 +12,13 @@ module PhpCop
12
12
  TAG_OPEN = ['\<\?php', '\<\?='].freeze
13
13
  TAG_CLOSE = ['\?\>'].freeze
14
14
 
15
- def initialize(file, line = nil, line_number = nil)
16
- super(file, line, line_number)
15
+ def initialize(file, path, line = nil, line_number = nil)
16
+ super(file, path, line, line_number)
17
17
  end
18
18
 
19
19
  def test_counters
20
20
  # Test if tags open is equal to tags close
21
- unless @count_open == @count_close
22
- return_an_error(@file, @line_number, 0)
23
- end
21
+ return_an_error(MSG_ALERT_DESCRIB) unless @count_open == @count_close
24
22
  end
25
23
 
26
24
  # Parse line and test if line use correctly tags PHP
data/lib/phpcop/runner.rb CHANGED
@@ -46,31 +46,31 @@ module PhpCop
46
46
  line_number = 0
47
47
  # Execute all test in file
48
48
  f = File.open(format('%s/%s', path, file), 'r')
49
- @php_tag = PhpCop::Cop::Files::PhpTags.new(file)
49
+ @php_tag = PhpCop::Cop::Files::PhpTags.new(file, path)
50
50
  while (line = f.gets)
51
- parse_file(file, line, line_number)
51
+ parse_file(file, line, line_number, path)
52
52
  line_number += 1
53
53
  end
54
54
  @php_tag.test_counters
55
55
  @count_errors += @php_tag.errors
56
56
  end
57
57
 
58
- def parse_file(file, line, line_number)
58
+ def parse_file(file, line, line_number, path)
59
59
  @rules.each do |value|
60
- parse_rule(value, file, line, line_number) if value.enabled
60
+ parse_rule(value, file, line, line_number, path) if value.enabled
61
61
  end
62
62
  end
63
63
 
64
- def parse_rule(rule, file, line, line_number)
64
+ def parse_rule(rule, file, line, line_number, path)
65
65
  case rule.name
66
66
  when 'phpTags'
67
67
  test_file_php_tags(line, line_number)
68
68
  when 'phpEncoding'
69
- test_file_php_encoding(file, line, line_number)
69
+ test_file_php_encoding(path, file, line, line_number)
70
70
  when 'methods'
71
- test_ccpm_methods(file, line, line_number)
71
+ test_ccpm_methods(path, file, line, line_number)
72
72
  when 'constants'
73
- test_ccpm_constants(file, line, line_number)
73
+ test_ccpm_constants(path, file, line, line_number)
74
74
  end
75
75
  end
76
76
 
@@ -78,18 +78,18 @@ module PhpCop
78
78
  @php_tag.test_line(line, line_number)
79
79
  end
80
80
 
81
- def test_file_php_encoding(file, line, line_number)
82
- test = PhpCop::Cop::Files::PhpEncoding.new(file, line, line_number)
81
+ def test_file_php_encoding(path, file, line, line_number)
82
+ test = PhpCop::Cop::Files::PhpEncoding.new(file, path, line, line_number)
83
83
  @count_errors += test.errors
84
84
  end
85
85
 
86
- def test_ccpm_methods(file, line, line_number)
87
- test = PhpCop::Cop::CCPM::Methods.new(file, line, line_number)
86
+ def test_ccpm_methods(path, file, line, line_number)
87
+ test = PhpCop::Cop::CCPM::Methods.new(file, path, line, line_number)
88
88
  @count_errors += test.errors
89
89
  end
90
90
 
91
- def test_ccpm_constants(file, line, line_number)
92
- test = PhpCop::Cop::CCPM::Constants.new(file, line, line_number)
91
+ def test_ccpm_constants(path, file, line, line_number)
92
+ test = PhpCop::Cop::CCPM::Constants.new(file, path, line, line_number)
93
93
  @count_errors += test.errors
94
94
  end
95
95
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Phpcop
5
- VERSION = '0.5.4'
5
+ VERSION = '0.5.6'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phpcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy VAILLANT