Completed
Branch master (37855a)
by Nikola
04:18
created

NamerCollection::joinKeyColumnName()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 8.2222
cc 7
eloc 12
nc 7
nop 2
crap 56
1
<?php
2
/*
3
 * This file is part of the Doctrine Naming Strategy Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy;
11
12
use Doctrine\ORM\Mapping\NamingStrategy;
13
14
class NamerCollection implements NamingStrategy
15
{
16
    const UNDERSCORE = 'underscore';
17
    const NOTHING = 'nothing';
18
    const UCFIRST = 'ucfirst';
19
20
    /**
21
     * @var NamingStrategy
22
     */
23
    protected $defaultNamer;
24
25
    /**
26
     * @var NamingStrategy[]
27
     */
28
    protected $concurrentNamers;
29
30
    /**
31
     * @var string
32
     */
33
    protected $concatenation;
34
35 4
    public function __construct(NamingStrategy $defaultNamer, array $concurrentNamers, $concatenation = self::UNDERSCORE)
36
    {
37 4
        $this->defaultNamer = $defaultNamer;
38 4
        $this->concurrentNamers = $concurrentNamers;
39 4
        $this->concatenation = $concatenation;
40 4
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 4
    public function classToTableName($className)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
46
    {
47 4
        $defaultName = $this->defaultNamer->classToTableName($className);
48
49
        /**
50
         * @var NamingStrategy $concurrentNamer
51
         */
52 4
        foreach ($this->concurrentNamers as $concurrentNamer) {
53
54 4
            if (($newProposal = $concurrentNamer->classToTableName($className)) != $defaultName) {
55 4
                return $newProposal;
56
            }
57 1
        }
58
59
        return $defaultName;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function propertyToColumnName($propertyName, $className = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
66
    {
67
        $defaultName = $this->defaultNamer->propertyToColumnName($propertyName, $className);
68
69
        /**
70
         * @var NamingStrategy $concurrentNamer
71
         */
72
        foreach ($this->concurrentNamers as $concurrentNamer) {
73
74
            if (($newProposal = $concurrentNamer->propertyToColumnName($propertyName, $className)) != $defaultName) {
75
                return $newProposal;
76
            }
77
        }
78
79
        return $defaultName;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
86
    {
87
        $defaultName = $this->defaultNamer->embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className, $embeddedClassName);
88
89
        /**
90
         * @var NamingStrategy $concurrentNamer
91
         */
92
        foreach ($this->concurrentNamers as $concurrentNamer) {
93
94
            if (($newProposal = $concurrentNamer->embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className, $embeddedClassName)) != $defaultName) {
95
                return $newProposal;
96
            }
97
        }
98
99
        return $defaultName;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function referenceColumnName()
106
    {
107
        $defaultName = $this->defaultNamer->referenceColumnName();
108
109
        /**
110
         * @var NamingStrategy $concurrentNamer
111
         */
112
        foreach ($this->concurrentNamers as $concurrentNamer) {
113
114
            if (($newProposal = $concurrentNamer->referenceColumnName()) != $defaultName) {
115
                return $newProposal;
116
            }
117
        }
118
119
        return $defaultName;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function joinColumnName($propertyName/*, $className = null*/)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
    {
127
        $defaultName = $this->defaultNamer->joinColumnName($propertyName/*, $className */);
128
129
        /**
130
         * @var NamingStrategy $concurrentNamer
131
         */
132
        foreach ($this->concurrentNamers as $concurrentNamer) {
133
134
            if (($newProposal = $concurrentNamer->joinColumnName($propertyName/*, $className */)) != $defaultName) {
135
                return $newProposal;
136
            }
137
        }
138
139
        return $defaultName;
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145 2
    public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
146
    {
147 2
        switch ($this->concatenation) {
148 2
            case self::UCFIRST:
149
                return $this->classToTableName($sourceEntity) . ucfirst($this->classToTableName($targetEntity));
150
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
151 2
            case self::NOTHING:
152
                return $this->classToTableName($sourceEntity) . $this->classToTableName($targetEntity);
153
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
154 2
            case self::UNDERSCORE: // FALL TROUGH
155 1
            default:
156 2
                return $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity);
157
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
158
        }
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    public function joinKeyColumnName($entityName, $referencedColumnName = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
165
    {
166
        switch ($this->concatenation) {
167
            case self::UCFIRST:
168
                return $this->classToTableName($entityName) . ucfirst(($referencedColumnName ?: $this->referenceColumnName()));
169
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
170
            case self::NOTHING:
171
                return $this->classToTableName($entityName) . ($referencedColumnName ?: $this->referenceColumnName());
172
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
173
            case self::UNDERSCORE: // FALL TROUGH
174
            default:
175
                return $this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName());
176
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
177
        }
178
    }
179
}
180