ThumbnailFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * Factory for creating thumbnail instances
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2015-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
class ThumbnailFactory
11
{
12
13
	const THUMBNAIL_TYPE_ACTOR = 'actor';
14
	const THUMBNAIL_TYPE_SEASON = 'season';
15
	const THUMBNAIL_TYPE_VIDEO = 'video';
16
17
	/**
18
	 * @var string[] list of placeholder images per thumbnail type
19
	 */
20
	private static $placeholderPaths = array(
21
		self::THUMBNAIL_TYPE_ACTOR => 'images/placeholder-actor.jpg',
22
		self::THUMBNAIL_TYPE_SEASON => 'images/placeholder-folder.jpg',
23
		self::THUMBNAIL_TYPE_VIDEO => 'images/placeholder-video.jpg'
24
	);
25
26
	/**
27
	 * Creates and returns a thumbnail instance
28
	 * @param string $imagePath the path to the image
29
	 * @param int $size the desired thumbnail size
30
	 * @param string $type the thumbnail type
31
	 * @return AbstractThumbnail
32
	 */
33
	public static function create($imagePath, $size, $type = self::THUMBNAIL_TYPE_VIDEO)
34
	{
35
		if (self::isPlaceHolderPath($imagePath))
36
		{
37
			$placeholderPath = self::$placeholderPaths[$type];
38
			return new PlaceholderThumbnail($placeholderPath);
39
		}
40
		else
41
			return new Thumbnail($imagePath, $size);
42
	}
43
44
	/**
45
	 * Returns whether the specified path points to a placeholder image.
46
	 * A placeholder path can either be empty or begin with image://placeholder
47
	 * @param $path the path to check
0 ignored issues
show
Bug introduced by
The type the was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
	 * @return bool
49
	 */
50
	private static function isPlaceHolderPath($path)
51
	{
52
		return empty($path) ||
53
				substr($path, 0, strlen('image://placeholder')) === 'image://placeholder';
54
	}
55
56
	/**
57
	 * Prevent construction
58
	 */
59
	private function __construct()
60
	{
61
		
62
	}
63
64
}
65