Completed
Pull Request — develop (#7)
by
unknown
03:21
created

ValueDriver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 31
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C generator() 0 22 7
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
11
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
12
 * THE SOFTWARE.
13
 */
14
15
namespace Ytake\Lom\Factory;
16
17
use PhpParser\Node\Stmt\Class_;
18
19
/**
20
 * Class ValueDriver.
21
 *
22
 * @author  yuuki.takezawa<[email protected]>
23
 * @license http://opensource.org/licenses/MIT MIT
24
 */
25
class ValueDriver extends AbstractDriver implements FactoryInterface
26
{
27
    // getter generator
28
    use GetterTrait, ToStringTrait;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function generator(): ?array
34
    {
35
        foreach ($this->reflector->getProperties() as $property) {
36
            $name = $property->getName();
37
            $this->createGetter($name);
38
        }
39
        foreach ($this->parsed as $part) {
40
            if ($part instanceof Class_) {
41
                foreach ($this->getGetters() as $getter) {
42
                    if ($this->reflector->hasMethod($getter['method'])) {
43
                        continue;
44
                    }
45
                    $part->stmts[] = $this->createGetterMethod($getter);
46
                }
47
                if (!$this->reflector->hasMethod('__toString')) {
48
                    $part->stmts[] = $this->createToString($this->getGetters());
49
                }
50
            }
51
        }
52
53
        return $this->parsed;
54
    }
55
}
56