Completed
Push — master ( 2b7a2e...74ad36 )
by Michael
11:15
created

OperationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 23
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 18 3
1
<?php
2
	/**
3
##DOC-SIGNATURE##
4
5
    This file is part of WideImage.
6
		
7
    WideImage is free software; you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as published by
9
    the Free Software Foundation; either version 2.1 of the License, or
10
    (at your option) any later version.
11
		
12
    WideImage is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16
		
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with WideImage; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
	* @package Internals
22
  **/
23
24
namespace WideImage;
25
26
use WideImage\Operation;
27
use WideImage\Exception\UnknownImageOperationException;
28
29
/**
30
 * Operation factory
31
 * 
32
 * @package Internals
33
 **/
34
class OperationFactory
35
{
36
	protected static $cache = array();
37
	
38
	public static function get($operationName)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
39
	{
40
		$lcname = strtolower($operationName);
41
		
42
		if (!isset(self::$cache[$lcname])) {
43
			$opClassName = "\\WideImage\\Operation\\" . ucfirst($operationName);
44
			
45
			// why not use autoloading?			
46
			// if (!class_exists($opClassName, false)) {
47
			if (!class_exists($opClassName)) {
48
				throw new UnknownImageOperationException("Can't load '{$operationName}' operation.");
49
			}
50
			
51
			self::$cache[$lcname] = new $opClassName();
52
		}
53
		
54
		return self::$cache[$lcname];
55
	}
56
}
57