Conditions | 12 |
Paths | 128 |
Total Lines | 47 |
Code Lines | 25 |
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 |
||
64 | final protected function execute() |
||
65 | { |
||
66 | $classType = Framework::isCli() ? 'Command' : 'Controller'; |
||
67 | $route = $this->router()->getRoute( |
||
68 | $this->request()->getTarget(), |
||
69 | $this->router()->setting('routes'), |
||
70 | $this->request()->getArgs() |
||
71 | ); |
||
72 | |||
73 | $class = isset($route[0]) ? $route[0] : null; |
||
74 | $method = isset($route[1]) ? $route[1] : null; |
||
75 | $args = isset($route[2]) ? $route[2] : []; |
||
76 | |||
77 | if (empty($class) || empty($method)) { |
||
78 | throw new ApplicationException("Invalid route"); |
||
79 | } |
||
80 | |||
81 | $className = sprintf("\\%s\\Domain\\%s\\%s", $this->projectNamespace, $class, $classType); |
||
82 | if (!class_exists($className)) { |
||
83 | /* enable in V10 * |
||
84 | throw new NotFoundException( |
||
85 | sprintf('No matching %s found', $classType) |
||
86 | ); |
||
87 | /* enable in V10 */ |
||
88 | |||
89 | /* remove in V10 */ |
||
90 | // check for v9 class name |
||
91 | $className = sprintf("\\%s\\Domain\\%s\\%s%s", $this->projectNamespace, $class, $class, $classType); |
||
92 | if (!class_exists($className)) { |
||
93 | throw new NotFoundException( |
||
94 | sprintf('No matching %s found', $classType) |
||
95 | ); |
||
96 | } |
||
97 | /* remove in V10 */ |
||
98 | } |
||
99 | |||
100 | $object = new $className; |
||
101 | $parent = get_parent_class($object); |
||
102 | if (method_exists((string) $parent, $method) || |
||
103 | !is_callable([$className, $method])) { |
||
104 | throw new NotFoundException('No matching Action found'); |
||
105 | } |
||
106 | $callable = [$object, $method]; |
||
107 | if (!is_callable($callable)) { |
||
108 | throw new ApplicationException('Method not found'); |
||
109 | } |
||
110 | return call_user_func_array($callable, $args); |
||
111 | } |
||
135 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.