DoctrineManagerGenerator::generate()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 19

Duplication

Lines 7
Ratio 22.58 %

Code Coverage

Tests 20
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 31
rs 8.8571
ccs 20
cts 20
cp 1
cc 2
eloc 19
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Pgs\RestfonyBundle\Generator;
4
5
use Pgs\RestfonyBundle\Generator\Helper\BundleStructureHelper;
6
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
7
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
8
9
class DoctrineManagerGenerator extends Generator
10
{
11
    /**
12
     * @var BundleStructureHelper
13
     */
14
    protected $helper;
15
16 2
    public function __construct(BundleInterface $bundle, $entity)
17
    {
18 2
        $this->helper = new BundleStructureHelper($bundle, $entity);
19 2
    }
20
21 1
    protected function canWriteToFile($forceOverwrite)
22
    {
23 1
        return !file_exists($this->helper->getManagerFullFilename()) || $forceOverwrite;
0 ignored issues
show
Documentation Bug introduced by
The method getManagerFullFilename does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
24
    }
25
26
    /**
27
     * Generates the entity form class if it does not exist.
28
     *
29
     * @param bool              $forceOverwrite
30
     */
31 2
    public function generate($forceOverwrite = false)
32
    {
33 2 View Code Duplication
        if (!$this->canWriteToFile($forceOverwrite)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34 1
            throw new \RuntimeException(sprintf(
35 1
                'Unable to generate the %s manager class as it already exists under the file: %s',
36 1
                $this->helper->getEntityClass() . 'Type',
0 ignored issues
show
Documentation Bug introduced by
The method getEntityClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
37 1
                $this->helper->getManagerFullFilename()
0 ignored issues
show
Documentation Bug introduced by
The method getManagerFullFilename does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
38
            ));
39
        }
40
41 1
        $this->renderFile(
42 1
            'manager/manager.php.twig',
43 1
            $this->helper->getManagerFullFilename(),
0 ignored issues
show
Documentation Bug introduced by
The method getManagerFullFilename does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
44
            [
45 1
                'repository_class' => $this->helper->getRepositoryFullClass(),
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryFullClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
46 1
                'class' => $this->helper->getManagerClass(),
0 ignored issues
show
Documentation Bug introduced by
The method getManagerClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47 1
                'namespace' => $this->helper->getManagerNamespace()
0 ignored issues
show
Documentation Bug introduced by
The method getManagerNamespace does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
            ]
49
        );
50
51 1
        $this->renderFile(
52 1
            'manager/interface.php.twig',
53 1
            $this->helper->getManagerFullFilename($this->helper->getManagerClass() . 'Interface.php'),
0 ignored issues
show
Documentation Bug introduced by
The method getManagerClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Documentation Bug introduced by
The method getManagerFullFilename does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
            [
55 1
                'bundle_namespace' => $this->helper->getBundleNamespace(),
56 1
                'entity_class' => $this->helper->getEntityClass(),
0 ignored issues
show
Documentation Bug introduced by
The method getEntityClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57 1
                'class' => $this->helper->getManagerClass(),
0 ignored issues
show
Documentation Bug introduced by
The method getManagerClass does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
58 1
                'namespace' => $this->helper->getManagerNamespace()
0 ignored issues
show
Documentation Bug introduced by
The method getManagerNamespace does not exist on object<Pgs\RestfonyBundl...\BundleStructureHelper>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59
            ]
60
        );
61 1
    }
62
}
63