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

GenericFactory::isResolvable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
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