Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 24 | class HelpManHandler |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $path; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $manBinary; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var ExecutableFinder |
||
| 38 | */ |
||
| 39 | private $executableFinder; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var ProcessLauncher |
||
| 43 | */ |
||
| 44 | private $processLauncher; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Creates a new AsciiDoc descriptor. |
||
| 48 | * |
||
| 49 | * @param ExecutableFinder $executableFinder The finder used to find the |
||
|
|
|||
| 50 | * "man" binary. |
||
| 51 | * @param ProcessLauncher $processLauncher The launcher for executing the |
||
| 52 | * "man" binary. |
||
| 53 | */ |
||
| 54 | 19 | View Code Duplication | public function __construct($path, ExecutableFinder $executableFinder = null, ProcessLauncher $processLauncher = null) |
| 55 | { |
||
| 56 | 19 | Assert::file($path); |
|
| 57 | |||
| 58 | 19 | $this->path = $path; |
|
| 59 | 19 | $this->executableFinder = $executableFinder ?: new ExecutableFinder(); |
|
| 60 | 19 | $this->processLauncher = $processLauncher ?: new ProcessLauncher(); |
|
| 61 | 19 | } |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 17 | public function handle() |
|
| 67 | { |
||
| 68 | 17 | if (!$this->processLauncher->isSupported()) { |
|
| 69 | 1 | throw new RuntimeException('The ProcessLauncher must be supported for the man help to run.'); |
|
| 70 | } |
||
| 71 | |||
| 72 | 16 | if (!$this->manBinary) { |
|
| 73 | 10 | $this->manBinary = $this->executableFinder->find('man'); |
|
| 74 | } |
||
| 75 | |||
| 76 | 16 | if (!$this->manBinary) { |
|
| 77 | 1 | throw new RuntimeException('The "man" binary was not found.'); |
|
| 78 | } |
||
| 79 | |||
| 80 | 15 | return $this->processLauncher->launchProcess( |
|
| 81 | 15 | escapeshellcmd($this->manBinary).' -l %path%', |
|
| 82 | 15 | array('path' => $this->path), |
|
| 83 | 15 | false |
|
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public function getManBinary() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param string $manBinary |
||
| 97 | */ |
||
| 98 | 14 | public function setManBinary($manBinary) |
|
| 102 | } |
||
| 103 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.