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 |
||
| 10 | class AssetLibraryServiceProvider extends ServiceProvider |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Indicates if loading of the provider is deferred. |
||
| 14 | * |
||
| 15 | * @var bool |
||
| 16 | */ |
||
| 17 | protected $defer = false; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Perform post-registration booting of services. |
||
| 21 | * |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | 53 | public function boot() |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Register factories. |
||
| 40 | * |
||
| 41 | * @param string $path |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | 53 | protected function registerEloquentFactoriesFrom($path) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Define the routes for the application. |
||
| 51 | * |
||
| 52 | * @param \Illuminate\Routing\Router $router |
||
| 53 | * @return void |
||
| 54 | */ |
||
| 55 | public function setupRoutes(Router $router) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Register any package services. |
||
| 64 | * |
||
| 65 | * @return void |
||
| 66 | */ |
||
| 67 | 53 | public function register() |
|
| 73 | |||
| 74 | 53 | protected function registerModelBindings() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * |
||
| 81 | */ |
||
| 82 | private function registerAssetLibrary() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * |
||
| 91 | */ |
||
| 92 | 53 | public function publishMigrations(): void |
|
| 115 | } |
||
| 116 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: