Class: PhpCop::Cop::Files::PhpTags

Inherits:
Cop
  • Object
show all
Defined in:
lib/phpcop/cop/files/phptags.rb

Overview

This class test file php use correctly tags PHP ‘<?php ?>’ or ‘<?= ?>’

Constant Summary collapse

MSG_ALERT_DESCRIB =
'Dont use correctly PHP Tags.'
TAG_OPEN =
['\<\?php', '\<\?='].freeze
TAG_CLOSE =
['\?\>'].freeze

Constants inherited from Cop

Cop::MSG_ALERT_FILE

Instance Attribute Summary collapse

Attributes inherited from Cop

#errors

Instance Method Summary collapse

Constructor Details

#initialize(file, path, line = nil, line_number = nil) ⇒ PhpTags

Returns a new instance of PhpTags.



15
16
17
# File 'lib/phpcop/cop/files/phptags.rb', line 15

def initialize(file, path, line = nil, line_number = nil)
  super(file, path, line, line_number)
end

Instance Attribute Details

#count_closeObject (readonly)

Returns the value of attribute count_close.



9
10
11
# File 'lib/phpcop/cop/files/phptags.rb', line 9

def count_close
  @count_close
end

#count_openObject (readonly)

Returns the value of attribute count_open.



9
10
11
# File 'lib/phpcop/cop/files/phptags.rb', line 9

def count_open
  @count_open
end

Instance Method Details

#test_countersObject



19
20
21
22
# File 'lib/phpcop/cop/files/phptags.rb', line 19

def test_counters
  # Test if tags open is equal to tags close
  return_an_error(MSG_ALERT_DESCRIB) unless @count_open == @count_close
end

#test_line(line, line_number) ⇒ Object

Parse line and test if line use correctly tags PHP



25
26
27
28
29
30
31
32
# File 'lib/phpcop/cop/files/phptags.rb', line 25

def test_line(line, line_number)
  @line = line
  @line_number = line_number
  # Parse file and search tags exists
  parse_and_search_open_tag
  # If file contains tag <?php or <?= search close tags
  parse_and_search_close_tag
end