GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EntityAttacher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 52
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B setEntity() 0 25 5
1
<?php
2
/*
3
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
5
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
6
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
7
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
 */
10
11
namespace MpaCustomDoctrineHydrator\Services;
12
13
use Doctrine\Common\Persistence\ObjectManager;
14
use Doctrine\ORM\EntityManager;
15
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
16
use MpaCustomDoctrineHydrator\Interfaces\EntityAttacherInterface;
17
use MpaCustomDoctrineHydrator\Stdlib\Hydrator\Strategy\FormatConversionStrategy;
18
19
class EntityAttacher implements EntityAttacherInterface
20
{
21
    /** @var $objectManager EntityManager */
22
    protected $objectManager;
23
    protected $dateConfig;
24
    protected $doctrineObject;
25
26
    /**
27
     * @param ObjectManager  $objectManager
28
     * @param array          $dateConfig
29
     * @param DoctrineObject $doctrineObject
30
     */
31 2
    public function __construct(
32
        ObjectManager $objectManager,
33
        array $dateConfig,
34
        DoctrineObject $doctrineObject
35
    ) {
36 2
        $this->objectManager  = $objectManager;
37 2
        $this->dateConfig     = $dateConfig;
38 2
        $this->doctrineObject = $doctrineObject;
39 2
    }
40
41
    /**
42
     * @param  string $entity
43
     * @return DoctrineObject
44
     */
45 2
    public function setEntity($entity)
46
    {
47 2
        $columns = $this->objectManager->getClassMetadata($entity)->getColumnNames();
48 2
        foreach ($columns as $column) {
49 2
            $type = $this->objectManager->getClassMetadata($entity)->getTypeOfColumn($column);
50 2
            if ('date' === $type) {
51 2
                $this->doctrineObject->addStrategy(
52
                    $column,
53 2
                    new FormatConversionStrategy($this->dateConfig['date_format'])
54
                );
55 2
            } elseif ('datetime' === $type) {
56 2
                $this->doctrineObject->addStrategy(
57
                    $column,
58 2
                    new FormatConversionStrategy($this->dateConfig['datetime_format'])
59
                );
60 2
            } elseif ('time' === $type) {
61 2
                $this->doctrineObject->addStrategy(
62
                    $column,
63 2
                    new FormatConversionStrategy($this->dateConfig['time_format'])
64
                );
65
            }
66
        }
67
68 2
        return $this->doctrineObject;
69
    }
70
}
71