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 Debug |
||
22 | { |
||
23 | protected static $messages = [ |
||
24 | 403 => [ |
||
25 | "This indicates a problem with authorization.\n", |
||
26 | "Please ensure that the credentials you created for this script\n", |
||
27 | "have the necessary permissions in the Luna portal.\n", |
||
28 | ], |
||
29 | 400 => [ |
||
30 | 'This indicates a problem with authentication or headers.', |
||
31 | 'Please ensure that the .edgerc file is formatted correctly.', |
||
32 | 'If you still have issues, please use gen_edgerc.php to generate the credentials', |
||
33 | ], |
||
34 | 401 => 400, |
||
35 | 404 => [ |
||
36 | "This means that the page does not exist as requested.\n", |
||
37 | "Please ensure that the URL you're calling is correctly formatted\n", |
||
38 | "or look at other examples to make sure yours matches.\n", |
||
39 | ] |
||
40 | ]; |
||
41 | |||
42 | protected $fp; |
||
43 | |||
44 | /** |
||
45 | * Debug constructor. |
||
46 | * |
||
47 | * This method accepts a stream resource or a valid stream URL |
||
48 | * (including file paths). If none is passed in stderr is used. |
||
49 | * |
||
50 | * @param resource|null $resource |
||
51 | * @throws \Akamai\Open\EdgeGrid\Exception\HandlerException\IOException |
||
52 | */ |
||
53 | 18 | public function __construct($resource = null) |
|
70 | |||
71 | /** |
||
72 | * Handle the request/response |
||
73 | * |
||
74 | * @param callable $handler |
||
75 | * @return \Closure |
||
76 | */ |
||
77 | 16 | public function __invoke(callable $handler) |
|
148 | } |
||
149 |