| Total Complexity | 8 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class ImageService |
||
| 18 | { |
||
| 19 | private static $instance; |
||
| 20 | /** |
||
| 21 | * @var Storage |
||
| 22 | */ |
||
| 23 | protected $storage; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * ImageService constructor. |
||
| 27 | */ |
||
| 28 | protected function __construct() |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return ImageService |
||
| 34 | */ |
||
| 35 | public static function getInstance() |
||
| 36 | { |
||
| 37 | if (!self::$instance instanceof ImageService) { |
||
| 38 | self::$instance = new ImageService(); |
||
| 39 | } |
||
| 40 | return self::$instance; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param $imagePath |
||
| 45 | * @return Image |
||
| 46 | */ |
||
| 47 | public static function get($imagePath) |
||
| 48 | { |
||
| 49 | $instance = self::getInstance(); |
||
| 50 | return $instance->getImageByPath($imagePath); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function __toString() |
||
| 57 | { |
||
| 58 | return (string)print_r(self::$instance, true); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param $imagePath |
||
| 63 | * @return Image|null |
||
| 64 | */ |
||
| 65 | protected function getImageByPath($imagePath) |
||
| 66 | { |
||
| 67 | $image = $this->storage->getImages()->getImageByName($imagePath); |
||
| 68 | return $image === null ? null : new Image($image); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param Storage $storage |
||
| 73 | */ |
||
| 74 | public function init(Storage $storage) |
||
| 77 | } |
||
| 78 | } |