Completed
Push — master ( 4d7d0c...65bf09 )
by Mathieu
02:04
created

GenericFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 9 2
A isResolvable() 0 9 2
1
<?php
2
3
namespace Charcoal\Factory;
4
5
use \InvalidArgumentException;
6
7
// Local namespace dependencies
8
use \Charcoal\Factory\AbstractFactory;
9
10
/**
11
 *
12
 */
13
class GenericFactory extends AbstractFactory
14
{
15
    /**
16
     * @param string $type The "type" of object to resolve (the object ident).
17
     * @throws InvalidArgumentException If the type parameter is not a string.
18
     * @return string
19
     */
20
    public function resolve($type)
21
    {
22
        if (!is_string($type)) {
23
            throw new InvalidArgumentException(
24
                'Can not resolve class ident: type must be a string'
25
            );
26
        }
27
        return $type;
28
    }
29
30
    /**
31
     * @param string $type The "type" of object to resolve (the object ident).
32
     * @throws InvalidArgumentException If the type parameter is not a string.
33
     * @return boolean
34
     */
35
    public function isResolvable($type)
36
    {
37
        if (!is_string($type)) {
38
            throw new InvalidArgumentException(
39
                'Can not check resolvable: type must be a string'
40
            );
41
        }
42
        return !!class_exists($type);
43
    }
44
}
45