Completed
Pull Request — master (#2)
by Pedro
01:50
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 30
ccs 5
cts 8
cp 0.625
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProxy() 0 4 1
A create() 0 14 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
use Pcelta\Doctrine\Cache\Factory;
9
10
class Factory
11
{
12
    /**
13
     * @param Proxy $proxy
14
     */
15
    public function setProxy(Proxy $proxy)
16
    {
17
        $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...
18
    }
19 1
20
    /**
21
     * @param array $cacheSettings
22
     * @return CacheProvider
23
     * @throws InvalidCacheConfig
24
     */
25 1
    public function create(array $cacheSettings)
26
    {
27
        $config = new Config($cacheSettings);
28
29
        $class = sprintf('\Pcelta\Doctrine\Cache\Factory\%sFactory', $config->getAdapterName());
30
31 1
        if (!class_exists($class)) {
32
            throw new InvalidCacheConfig('Adapter not found');
33 1
        }
34 1
35
        /** @var Factory\AbstractFactory $factory */
36
        $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...
37
        return $this->factory->create($config);
38
    }
39
}
40