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 |
||
| 35 | class Pages extends Mapper |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * Fields and their visibility to clients, boolean or string of visible field name |
||
| 39 | * |
||
| 40 | * @var array $fieldsVisible |
||
| 41 | * @link https://github.com/Wixel/GUMP |
||
| 42 | */ |
||
| 43 | public $fieldsVisible = [ |
||
| 44 | 'uuid' => 'id', |
||
| 45 | 'users_uuid' => 'user_id', |
||
| 46 | ]; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Fields that are editable to clients, boolean or string of visible field name |
||
| 50 | * |
||
| 51 | * @var array $fieldsEditable |
||
| 52 | */ |
||
| 53 | protected $fieldsEditable = [ |
||
| 54 | 'key', |
||
| 55 | 'author', |
||
| 56 | 'language', |
||
| 57 | 'status', |
||
| 58 | 'slug', |
||
| 59 | 'path', |
||
| 60 | 'keywords', |
||
| 61 | 'description', |
||
| 62 | 'title', |
||
| 63 | 'summary', |
||
| 64 | 'body', |
||
| 65 | 'scopes', |
||
| 66 | 'category', |
||
| 67 | 'tags', |
||
| 68 | 'metadata', |
||
| 69 | 'published', |
||
| 70 | 'robots', |
||
| 71 | ]; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Filter rules for fields |
||
| 75 | * |
||
| 76 | * @var array $filterRules |
||
| 77 | * @link https://github.com/Wixel/GUMP |
||
| 78 | */ |
||
| 79 | public $filterRules = [ |
||
| 80 | 'uuid' => 'trim|sanitize_string|lower', |
||
| 81 | 'users_uuid' => 'trim|sanitize_string|lower', |
||
| 82 | 'key' => 'trim|sanitize_string|lower|slug', |
||
| 83 | 'author' => 'trim|sanitize_string', |
||
| 84 | 'language' => 'trim|sanitize_string|lower', |
||
| 85 | 'status' => 'trim|sanitize_string|lower', |
||
| 86 | 'slug' => 'trim|sanitize_string|lower|slug', |
||
| 87 | 'path' => 'trim|sanitize_string|lower', |
||
| 88 | 'keywords' => 'trim|sanitize_string|lower', |
||
| 89 | 'description' => 'trim|sanitize_string', |
||
| 90 | 'title' => 'trim|sanitize_string', |
||
| 91 | 'summary' => 'trim|sanitize_string', |
||
| 92 | 'body' => 'trim|sanitize_string', |
||
| 93 | 'scopes' => 'trim|sanitize_string|lower', |
||
| 94 | 'category' => 'trim|sanitize_string|lower', |
||
| 95 | 'tags' => 'trim|sanitize_string|lower', |
||
| 96 | 'metadata' => 'trim', |
||
| 97 | 'created' => 'trim|sanitize_string', |
||
| 98 | 'published' => 'trim|sanitize_string', |
||
| 99 | 'updated' => 'trim|sanitize_string', |
||
| 100 | 'robots' => 'trim|sanitize_numbers|whole_number', |
||
| 101 | ]; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Validation rules for fields |
||
| 105 | * |
||
| 106 | * @var array $validationRules |
||
| 107 | * @link https://github.com/Wixel/GUMP |
||
| 108 | */ |
||
| 109 | public $validationRules = [ |
||
| 110 | 'uuid' => 'alpha_dash', |
||
| 111 | 'users_uuid' => 'alpha_dash', |
||
| 112 | 'robots' => 'numeric', |
||
| 113 | ]; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Path in assets folder to user page images |
||
| 117 | * |
||
| 118 | * @var string $pageImagePath |
||
| 119 | */ |
||
| 120 | protected $pageImagePath = '/img/pages/'; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Default page image name |
||
| 124 | * |
||
| 125 | * @var string $pageImageFileName |
||
| 126 | */ |
||
| 127 | protected $pageImageFileName = 'page.png'; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Return the on-the-fly dynamic image generation URL path |
||
| 131 | * |
||
| 132 | * @param array $params params to url |
||
| 133 | * @return string return the url path or false if not exists |
||
| 134 | */ |
||
| 135 | public function pageImageUrlDynamic(array $params = []) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Return the URL path to the image if exists or false |
||
| 143 | * |
||
| 144 | * @return string return the url path or false if not exists |
||
| 145 | */ |
||
| 146 | public function pageImageUrlPath($filename = null): string |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Create if needed, and return the dir to the page image |
||
| 157 | * |
||
| 158 | * @return string $dir to the page image |
||
| 159 | */ |
||
| 160 | public function pageImageDirPath(): string |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Create if needed, and return the path to the page image |
||
| 168 | * |
||
| 169 | * @param null|string $filename filename for image |
||
| 170 | * @return string $path to the page image |
||
| 171 | */ |
||
| 172 | public function pageImageFilePath($filename = null): string |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Return the URL path to the image if exists or false |
||
| 182 | * |
||
| 183 | * @return boolean $path to the page image |
||
| 184 | * @return boolean true if the page image exists |
||
| 185 | */ |
||
| 186 | public function pageImageExists($filename = null) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Return the URL path to the image if exists or false |
||
| 193 | * |
||
| 194 | * @param string $filename |
||
| 195 | * @return false|string return the url path or false if not exists |
||
| 196 | */ |
||
| 197 | public function pageImageUrl($filename = null) |
||
| 205 | |||
| 206 | |||
| 207 | /** |
||
| 208 | * Create page image from given file |
||
| 209 | * |
||
| 210 | * @param string $file path to file |
||
| 211 | * @return boolean if the file was written and and asset record created |
||
| 212 | */ |
||
| 213 | public function pageImageCreate($file) |
||
| 273 | } |
||
| 274 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: