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 |
||
| 21 | class File extends FSAbstract{ |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $name; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var \chillerlan\Filereader\Directory |
||
| 30 | */ |
||
| 31 | protected $directory; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * File constructor. |
||
| 35 | * |
||
| 36 | * @param \chillerlan\Filereader\Drivers\FSDriverInterface $driver |
||
| 37 | * @param \chillerlan\Filereader\Directory $directory |
||
| 38 | * @param string $name |
||
| 39 | */ |
||
| 40 | public function __construct(FSDriverInterface $driver, Directory $directory, string $name){ |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return bool |
||
| 50 | */ |
||
| 51 | public function exists():bool{ |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function content():string{ |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return mixed |
||
| 64 | */ |
||
| 65 | public function getRequire(){ |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $destination |
||
| 71 | * @param bool $overwrite |
||
| 72 | * |
||
| 73 | * @return bool |
||
| 74 | */ |
||
| 75 | public function copy(string $destination, bool $overwrite = true):bool{ |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $newname |
||
| 81 | * @param bool $overwrite |
||
| 82 | * |
||
| 83 | * @return \chillerlan\Filereader\File |
||
| 84 | * @throws \chillerlan\Filereader\FilereaderException |
||
| 85 | */ |
||
| 86 | public function rename(string $newname, bool $overwrite = true):File{ |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return bool |
||
| 109 | */ |
||
| 110 | public function delete():bool{ |
||
| 113 | |||
| 114 | } |
||
| 115 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.