Conditions | 14 |
Paths | 169 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 5 |
Ratio | 8.93 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
19 | public function __construct($method) |
||
20 | { |
||
21 | // PHP 5.1 compat (Docs don't correctly show which version ReflectionFunctionAbstract was added) |
||
22 | if (!($method instanceof ReflectionMethod) && !($method instanceof ReflectionFunction)) { |
||
23 | throw new InvalidArgumentException('Argument must be an instance of ReflectionFunctionAbstract'); |
||
24 | } |
||
25 | |||
26 | $this->name = $method->getName(); |
||
27 | $this->filename = $method->getFilename(); |
||
28 | $this->startline = $method->getStartLine(); |
||
29 | $this->endline = $method->getEndLine(); |
||
30 | $this->internal = $method->isInternal(); |
||
31 | $this->docstring = $method->getDocComment(); |
||
32 | |||
33 | foreach ($method->getParameters() as $param) { |
||
34 | $this->parameters[] = new Kint_Object_Parameter($param); |
||
35 | } |
||
36 | |||
37 | if (KINT_PHP70) { |
||
38 | $this->returntype = $method->getReturnType(); |
||
39 | if ($this->returntype) { |
||
40 | $this->returntype = (string) $this->returntype; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (!$this->returntype && $this->docstring) { |
||
45 | if (preg_match('/@return\s+(.*)\r?\n/m', $this->docstring, $matches)) { |
||
46 | if (!empty($matches[1])) { |
||
47 | $this->returntype = $matches[1]; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | if ($method instanceof ReflectionMethod) { |
||
53 | $this->static = $method->isStatic(); |
||
54 | $this->operator = $this->static ? Kint_Object::OPERATOR_STATIC : Kint_Object::OPERATOR_OBJECT; |
||
55 | $this->abstract = $method->isAbstract(); |
||
56 | $this->final = $method->isFinal(); |
||
57 | $this->owner_class = $method->getDeclaringClass()->name; |
||
58 | $this->access = Kint_Object::ACCESS_PUBLIC; |
||
59 | View Code Duplication | if ($method->isProtected()) { |
|
60 | $this->access = Kint_Object::ACCESS_PROTECTED; |
||
61 | } elseif ($method->isPrivate()) { |
||
62 | $this->access = Kint_Object::ACCESS_PRIVATE; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | $docstring = new Kint_Object_Representation_Docstring( |
||
67 | $this->docstring, |
||
68 | $this->filename, |
||
69 | $this->startline |
||
70 | ); |
||
71 | |||
72 | $docstring->implicit_label = true; |
||
73 | $this->addRepresentation($docstring); |
||
74 | } |
||
75 | |||
229 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.