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 |
||
12 | |||
13 | /** |
||
14 | * Extended GitHub API package class. |
||
15 | */ |
||
16 | View Code Duplication | abstract class Package extends BasePackage |
|
17 | { |
||
18 | /** |
||
19 | * Magic method to lazily create API objects |
||
20 | * |
||
21 | * @param string $name Name of property to retrieve |
||
22 | * |
||
23 | * @return Package GitHub API package object. |
||
24 | * |
||
25 | * @throws \InvalidArgumentException |
||
26 | */ |
||
27 | public function __get($name) |
||
28 | { |
||
29 | $class = __NAMESPACE__ . '\\' . $this->package . '\\' . ucfirst($name); |
||
30 | |||
31 | if (class_exists($class)) |
||
32 | { |
||
33 | if (false == isset($this->$name)) |
||
34 | { |
||
35 | $this->$name = new $class($this->options, $this->client); |
||
36 | } |
||
37 | |||
38 | return $this->$name; |
||
39 | } |
||
40 | |||
41 | return parent::__get($name); |
||
44 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.