Passed
Push — 4.1 ( cc1509...e0bb47 )
by Andrea
12:41
created

FiController::getEntityClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace Fi\CoreBundle\Controller;
3
4
use Fi\CoreBundle\Utils\Entity\Finder;
5
use Fi\CoreBundle\Utils\Entity\EntityUtils;
6
use Fi\CoreBundle\Utils\PermessiUtils;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
9
10
class FiController extends FiTabellaController
11
{
12
13
    protected $bundle;
14
    protected $controller;
15
    protected $permessi;
16
17 1
    public function __construct(ObjectManager $em, TokenStorageInterface $user)
18
    {
19 1
        $matches = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20 1
        $controllo = new \ReflectionClass(get_class($this));
21
22 1
        preg_match('/(.*)\\\(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches);
23 1
        if (count($matches) == 0) {
24 1
            preg_match('/(.*)(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches);
25
        }
26
27 1
        $this->bundle = ($matches[count($matches) - 2] ? $matches[count($matches) - 2] : $matches[count($matches) - 3]);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28 1
        $this->controller = $matches[count($matches) - 1];
29
30 1
        $this->permessi = new PermessiUtils($em, $this->getController(), $user->getToken()->getUser());
31 1
    }
32
33
    /**
34
     * Returns the calling function through a backtrace
35
     */
36 1
    protected function getThisFunctionName()
37
    {
38
        // a funciton x has called a function y which called this
39
        // see stackoverflow.com/questions/190421
40 1
        $caller = debug_backtrace();
41 1
        $caller = $caller[1];
42 1
        return $caller['function'];
43
    }
44
45 1
    protected function getEntityClassNotation()
46
    {
47 1
        $em = $this->get("doctrine")->getManager();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal doctrine does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
48 1
        $entityfinder = new Finder($em, $this->controller);
49 1
        $entityutils = new EntityUtils($em);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
50 1
        return $entityutils->getClassNameToShortcutNotations($entityfinder->getClassNameFromEntityName());
51
    }
52
53 1
    protected function getEntityClassName()
54
    {
55 1
        $em = $this->get("doctrine")->getManager();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal doctrine does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
56 1
        $entityfinder = new Finder($em, $this->controller);
57 1
        return $entityfinder->getClassNameFromEntityName();
58
    }
59
    
60
    protected function getNamespace()
61
    {
62
        return $this->namespace;
0 ignored issues
show
Bug Best Practice introduced by
The property namespace does not exist on Fi\CoreBundle\Controller\FiController. Did you maybe forget to declare it?
Loading history...
63
    }
64
65 1
    protected function getBundle()
66
    {
67 1
        return $this->bundle;
68
    }
69
70 1
    protected function getController()
71
    {
72 1
        return $this->controller;
73
    }
74
75 1
    protected function getPermessi()
76
    {
77 1
        return $this->permessi;
78
    }
79
}
80