Factory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Pcelta\Doctrine\Cache;
4
5
use Pcelta\Doctrine\Cache\Entity\Config;
6
use Doctrine\Common\Cache\CacheProvider;
7
use Pcelta\Doctrine\Cache\Exception\InvalidCacheConfig;
8
9
class Factory
10
{
11
    /**
12
     * @param Proxy $proxy
13
     */
14 1
    public function setProxy(Proxy $proxy)
15
    {
16 1
        $this->proxy = $proxy;
0 ignored issues
show
Bug introduced by
The property proxy does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17 1
    }
18
19
    /**
20
     * @param array $cacheSettings
21
     *
22
     * @return CacheProvider
23
     *
24
     * @throws InvalidCacheConfig
25
     */
26 2
    public function create(array $cacheSettings)
27
    {
28 2
        $config = new Config($cacheSettings);
29
30 2
        $class = sprintf('\Pcelta\Doctrine\Cache\Factory\%sFactory', $config->getAdapterName());
31
32 2
        if (!class_exists($class)) {
33 1
            throw new InvalidCacheConfig('Adapter not found');
34
        }
35
36
        /* @var Factory\AbstractFactory $factory */
37 1
        $this->factory = new $class();
0 ignored issues
show
Bug introduced by
The property factory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
39 1
        return $this->factory->create($config);
40
    }
41
}
42