| Total Complexity | 14 |
| Total Lines | 80 |
| Duplicated Lines | 21.25 % |
| Changes | 0 | ||
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 | class Image extends Model |
||
| 13 | { |
||
| 14 | use SoftDeletes; |
||
| 15 | |||
| 16 | protected $fillable = [ |
||
| 17 | 'path', 'filename', 'type', 'thumbnails', 'metadata', 'processed' |
||
| 18 | ]; |
||
| 19 | |||
| 20 | |||
| 21 | /******************************************************************************************************************* |
||
| 22 | ************************************************** HELPERS / DATA ************************************************* |
||
| 23 | *******************************************************************************************************************/ |
||
| 24 | /** |
||
| 25 | * @param null $size |
||
|
|
|||
| 26 | * @param bool|FALSE $onlyPath |
||
| 27 | * @return array|null|string |
||
| 28 | */ |
||
| 29 | public function thumbnails( $size = NULL, $onlyPath = FALSE ) |
||
| 30 | { |
||
| 31 | $sizesArray = []; |
||
| 32 | |||
| 33 | if ( is_null( $size ) ) |
||
| 34 | { |
||
| 35 | View Code Duplication | if ( is_array( $this->thumbnails ) ) |
|
|
2 ignored issues
–
show
|
|||
| 36 | { |
||
| 37 | foreach( $this->thumbnails as $sizeKey => $path ) |
||
| 38 | { |
||
| 39 | $sizesArray[ $sizeKey ] = $onlyPath ? $path : $this->url_to( $path ); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | View Code Duplication | } else |
|
|
1 ignored issue
–
show
|
|||
| 44 | { |
||
| 45 | if ( is_array( $this->thumbnails) ) |
||
| 46 | { |
||
| 47 | foreach( $this->thumbnails as $sizeKey => $path ) |
||
| 48 | { |
||
| 49 | if( $size == $sizeKey ) return $onlyPath ? $path : $this->url_to( $path ); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return $sizesArray; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public function url() |
||
| 61 | { |
||
| 62 | return $this->url_to( $this->path ); |
||
| 63 | } |
||
| 64 | |||
| 65 | /******************************************************************************************************************* |
||
| 66 | **************************************************** INTERNAL ***************************************************** |
||
| 67 | *******************************************************************************************************************/ |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param $value |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | public function getThumbnailsAttribute( $value ) |
||
| 74 | { |
||
| 75 | return json_decode( $value, TRUE ); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param $path |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | protected function url_to( $path ) |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | } |
||
| 96 |