Conditions | 10 |
Paths | 26 |
Total Lines | 87 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
75 | public function process() |
||
76 | { |
||
77 | if ($this->getConfiguration()->isConfigOutput()) { |
||
|
|||
78 | $configurationFiles = $this->getConfigurationFiles(); |
||
79 | $this->getSystemLogger()->info( |
||
80 | print_r($configurationFiles, true) |
||
81 | ); |
||
82 | return; |
||
83 | } |
||
84 | |||
85 | // load the actual status |
||
86 | $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); |
||
87 | |||
88 | // query whether or not the configured source directory is available |
||
89 | if (isset($status[RegistryKeys::SOURCE_DIRECTORY])) { |
||
90 | $sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY]; |
||
91 | } else { |
||
92 | throw new \Exception('Source directory is not available!'); |
||
93 | } |
||
94 | |||
95 | // try to load the archive directory |
||
96 | $archiveDir = $this->getConfiguration()->getArchiveDir(); |
||
97 | |||
98 | // try to initialize a default archive directory by concatenating 'archive' to the target directory |
||
99 | if ($archiveDir === null) { |
||
100 | $archiveDir = sprintf('var/import_history'); |
||
101 | } |
||
102 | |||
103 | // retrieve the question helper |
||
104 | $questionHelper = $this->getHelper('question'); |
||
105 | |||
106 | // initialize the array for the available serials |
||
107 | $availableSerials = array(); |
||
108 | |||
109 | // load the directories from the actual working directory (broken imports, etc.) |
||
110 | foreach (glob(sprintf('%s/*', $sourceDir), GLOB_ONLYDIR) as $possibleImportDir) { |
||
111 | $availableSerials[basename($possibleImportDir)] = filemtime($possibleImportDir); |
||
112 | } |
||
113 | |||
114 | // load the ZIP artefacts from the archive directory |
||
115 | foreach (glob(sprintf('%s/*.zip', $archiveDir)) as $possibleArtefact) { |
||
116 | $availableSerials[ basename($possibleArtefact, '.zip')] = filemtime($possibleArtefact); |
||
117 | } |
||
118 | |||
119 | // sort the available serials by modification time |
||
120 | uasort($availableSerials, function ($a, $b) { |
||
121 | // return zero, if the passed values are equal |
||
122 | if ($a == $b) { |
||
123 | return 0; |
||
124 | } |
||
125 | // otherwise return -1 or 1 |
||
126 | return ($a > $b) ? -1 : 1; |
||
127 | }); |
||
128 | |||
129 | // finally create the array with the available serials to render on the console |
||
130 | $availableSerials = array_slice(array_keys($availableSerials), 0, $this->getInput()->getOption(InputOptionKeysInterface::RENDER_DEBUG_SERIALS)); |
||
131 | |||
132 | // this is, when the import:debug send command has been invoked |
||
133 | // WITHOUT the --serial=<UUID> parameter or an invalid serial |
||
134 | if (!in_array($serial = $this->getSerial(), $availableSerials, true)) { |
||
135 | // create the question instance to choose the serial |
||
136 | $chooseSerialQuestion = new ChoiceQuestion('Please select the serial to create the debug artefact for', $availableSerials); |
||
137 | $chooseSerialQuestion->setErrorMessage('Selected serial "%s" is invalid.'); |
||
138 | |||
139 | // abort the operation if the user does not confirm with 'y' or enter |
||
140 | if (!$serial = $questionHelper->ask($this->getInput(), $this->getOutput(), $chooseSerialQuestion)) { |
||
141 | $this->getOutput()->writeln('<info>Aborting operation - debug report has NOT been sent.</info>'); |
||
142 | return; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | // update the registry with the (probably new) serial and the source directory |
||
147 | $this->getRegistryProcessor()->mergeAttributesRecursive( |
||
148 | RegistryKeys::STATUS, |
||
149 | array( |
||
150 | RegistryKeys::DEBUG_SERIAL => $serial, |
||
151 | RegistryKeys::SOURCE_DIRECTORY => sprintf('%s/%s', $sourceDir, $serial) |
||
152 | ) |
||
153 | ); |
||
154 | |||
155 | // prepare the debug dump |
||
156 | $this->getDebugUtil()->extractArchive($serial); |
||
157 | $this->getDebugUtil()->prepareDump($serial); |
||
158 | $dumpFilename = $this->getDebugUtil()->createDump($serial); |
||
159 | |||
160 | // write a success message to the console |
||
161 | $this->getOutput()->writeln(sprintf('<info>Successfully created debug dump "%s"</info>', $dumpFilename)); |
||
162 | } |
||
172 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.