Conditions | 8 |
Paths | 36 |
Total Lines | 68 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 2 | Features | 4 |
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 |
||
79 | public function handle() |
||
80 | { |
||
81 | // @todo should allow only registered instances to be called |
||
82 | |||
83 | $this->createFolders(); |
||
84 | $this->downloadDrivers(); |
||
85 | |||
86 | // Add build folder to path. |
||
87 | $this->env->addPathToGlobalPath($this->config->getBuildPath()); |
||
88 | |||
89 | // Warn if Chrome or Firefox binaries are not available. |
||
90 | if ($chromeVersion = $this->env->getChromeVersion()) { |
||
91 | $this->output->writeln('Chrome binary found, v.' . $chromeVersion); |
||
92 | } else { |
||
93 | $this->output->writeln('<info>WARNING: Chrome binary not found.</info>'); |
||
94 | } |
||
95 | |||
96 | if ($firefoxVersion = $this->env->getFirefoxVersion()) { |
||
97 | $this->output->writeln('Firefox binary found, v.' . $firefoxVersion); |
||
98 | } else { |
||
99 | $this->output->writeln('<info>WARNING: Firefox binary not found.</info>'); |
||
100 | } |
||
101 | |||
102 | // Warn if display is not available. |
||
103 | if ($this->env->isLinux()) { |
||
104 | if ($this->env->hasXvfb()) { |
||
105 | $this->output->writeln('<info>Xvfb is installed. Good.</info>'); |
||
106 | } else { |
||
107 | $this->output->writeln('<info>WARNING: Xvfb is not installed.</info>'); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | // $pid = $this->env->startDisplayProcess(); |
||
|
|||
112 | |||
113 | // Start Selenium Server instance. |
||
114 | $this->output->writeln( |
||
115 | sprintf('Starting Selenium Server (%s) ... %s:%s', $this->config->getName(), $this->config->getHostname(), $this->config->getPort()) |
||
116 | ); |
||
117 | |||
118 | $pid = $this->env->startSeleniumProcess(); |
||
119 | if ($pid > 0) { |
||
120 | // Make sure that we capture the right PID. |
||
121 | while ($this->env->listenToPort($this->config->getPort()) == '') { |
||
122 | $this->output->write('<info>.</info>'); |
||
123 | } |
||
124 | $parentPid = $this->env->getPidFromListeningToPort($this->config->getPort()); |
||
125 | if ($parentPid) { |
||
126 | $pid = $parentPid; |
||
127 | } |
||
128 | |||
129 | // @todo open the lock file only to update the status and ports, the instance was already added. |
||
130 | $this->locker->openLockFile(); |
||
131 | $this->locker->addServer( |
||
132 | ServerItemFactory::createFromProperties( |
||
133 | $this->config->getName(), |
||
134 | $pid, |
||
135 | $this->config->getPort(), |
||
136 | $this->config->getFilePath() |
||
137 | ) |
||
138 | ); |
||
139 | $this->locker->writeToLockFile(); |
||
140 | } |
||
141 | |||
142 | $this->output->writeln('<info>Done</info>'); |
||
143 | $this->output->writeln( |
||
144 | sprintf('Test it at http://%s:%s/wd/hub/', $this->config->getHostname(), $this->config->getPort()) |
||
145 | ); |
||
146 | } |
||
147 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.