DoctrineRepositoryGenerator::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 7
Ratio 35 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 20
rs 9.4285
ccs 13
cts 13
cp 1
cc 2
eloc 12
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 DoctrineRepositoryGenerator 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->getRepositoryFullFilename()) || $forceOverwrite;
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryFullFilename 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 Repository class as it already exists under the file: %s',
36 1
                $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...
37 1
                $this->helper->getRepositoryFullFilename()
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryFullFilename 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
            'repository/repository.php.twig',
43 1
            $this->helper->getRepositoryFullFilename(),
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryFullFilename 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
                'alias' => strtolower($this->helper->getEntityClass()[0]),
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...
46 1
                'class' => $this->helper->getRepositoryClass(),
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryClass 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->getRepositoryNamespace()
0 ignored issues
show
Documentation Bug introduced by
The method getRepositoryNamespace 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 1
    }
51
}
52