Conditions | 10 |
Paths | 10 |
Total Lines | 42 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
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 |
||
48 | public function getDependencies(): array |
||
49 | { |
||
50 | $ret = []; |
||
51 | |||
52 | foreach ($this->edge->getAttribute(DependencyGraph::DEPENDENCY_TYPE_KEY) as $dependencyType) { |
||
53 | /** @var DependencyType $dependencyType */ |
||
54 | if ($dependencyType instanceof MethodCall) { |
||
55 | $calleeFQSEN = $this->getDependeeClass()->createMethodFQSEN($dependencyType->getCallee()); |
||
56 | |||
57 | $callerFQSEN = !is_null($dependencyType->getCaller()) ? |
||
58 | $this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
||
59 | $this->getDependerClass(); |
||
60 | |||
61 | $ret[] = [$callerFQSEN, $calleeFQSEN]; |
||
62 | } elseif ($dependencyType instanceof PropertyFetch) { |
||
63 | $calleeFQSEN = $this->getDependeeClass()->createPropertyFQSEN($dependencyType->getPropertyName()); |
||
64 | |||
65 | $callerFQSEN = !is_null($dependencyType->getCaller()) ? |
||
66 | $this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
||
67 | $this->getDependerClass(); |
||
68 | |||
69 | $ret[] = [$callerFQSEN, $calleeFQSEN]; |
||
70 | } elseif ($dependencyType instanceof ConstantFetch) { |
||
71 | $calleeFQSEN = $this->getDependeeClass()->createClassConstantFQSEN($dependencyType->getConstantName()); |
||
72 | |||
73 | $callerFQSEN = !is_null($dependencyType->getCaller()) ? |
||
74 | $this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
||
75 | $this->getDependerClass(); |
||
76 | |||
77 | $ret[] = [$callerFQSEN, $calleeFQSEN]; |
||
78 | } elseif ($dependencyType instanceof NewObject) { |
||
79 | $callerFQSEN = !is_null($dependencyType->getCaller()) ? |
||
80 | $this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
||
81 | $this->getDependerClass(); |
||
82 | |||
83 | $ret[] = [$callerFQSEN, $this->getDependeeClass()]; |
||
84 | } else { |
||
85 | $ret[] = [$this->getDependerClass(), $this->getDependeeClass()]; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return $ret; |
||
90 | } |
||
92 |