Functions::getDeclarationLine()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 17
rs 9.8666
1
<?php
2
namespace Lepton\Helpers;
3
4
class Functions{
5
static function getDeclarationLine(\ReflectionProperty $prop){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6
  $declaringClass = $prop->getDeclaringClass();
7
  $propname = $prop->getName();
8
  $classFile      = new \SplFileObject($declaringClass->getFileName());
9
  foreach ($classFile as $line => $content) {
10
      if (preg_match(
11
          '/
12
              (private|protected|public|var|static) # match visibility or var
13
              \s                             # followed 1 whitespace
14
              \$'.$propname.'                          # followed by the var name $bar
15
          /x',
16
          $content)
0 ignored issues
show
Bug introduced by
It seems like $content can also be of type array; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
          /** @scrutinizer ignore-type */ $content)
Loading history...
17
      ) {
18
          return $line + 1;
19
      }
20
  }
21
  return 1;
22
}
23
}
24