Conditions | 11 |
Paths | 10 |
Total Lines | 40 |
Code Lines | 23 |
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 |
||
37 | public function getTasks() |
||
38 | { |
||
39 | $taskList = new TaskList; |
||
40 | |||
41 | if (!isset($this->document->tasks) || !is_array($this->document->tasks)) { |
||
42 | throw new ConfigurationException('No tasks found'); |
||
43 | } |
||
44 | |||
45 | foreach ($this->document->tasks as $taskJson) { |
||
46 | if (!isset($taskJson->name) || !isset($taskJson->src)) { |
||
47 | throw new ConfigurationException('Task name and src are required'); |
||
48 | } |
||
49 | |||
50 | $name = $taskJson->name; |
||
51 | $className = $taskJson->src; |
||
52 | $config = $taskJson->config; |
||
53 | |||
54 | if (!$name || !$className) { |
||
55 | throw new ConfigurationException('Task name and src cannot be empty'); |
||
56 | } |
||
57 | |||
58 | if (strpos($className, '\\') === false) { |
||
59 | $className = 'Genkgo\\Srvcleaner\\Tasks\\' . $className; |
||
60 | } |
||
61 | |||
62 | if (!class_exists($className)) { |
||
63 | throw new ConfigurationException("Task {$name} not found. Unknown class {$className}"); |
||
64 | } |
||
65 | |||
66 | $task = new $className ; |
||
67 | if ($task instanceof TaskInterface) { |
||
68 | $task->setConfig($config); |
||
69 | $taskList->add($name, $task); |
||
70 | } else { |
||
71 | throw new ConfigurationException("Task is not implementing TaskInterface"); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | return $taskList; |
||
76 | } |
||
77 | |||
96 |