PHPClassWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 13
loc 26
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A write() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace GoetasWebservices\Xsd\XsdToPhp\Writer;
3
4
use GoetasWebservices\Xsd\XsdToPhp\Php\PathGenerator\PathGenerator;
5
use Psr\Log\LoggerAwareInterface;
6
use Psr\Log\LoggerAwareTrait;
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
use Zend\Code\Generator\FileGenerator;
10
11
class PHPClassWriter implements LoggerAwareInterface
12
{
13
    use LoggerAwareTrait;
14
15
    protected $pathGenerator;
16
17
    public function __construct(PathGenerator $pathGenerator, LoggerInterface $logger = null)
18
    {
19
        $this->pathGenerator = $pathGenerator;
20
        $this->logger = $logger ?: new NullLogger();
21
    }
22
23 View Code Duplication
    public function write(array $items)
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...
24
    {
25
        foreach ($items as $item) {
26
            $path = $this->pathGenerator->getPath($item);
27
28
            $fileGen = new FileGenerator();
29
            $fileGen->setFilename($path);
30
            $fileGen->setClass($item);
31
            $fileGen->write();
32
            $this->logger->debug(sprintf("Written PHP class file %s", $path));
33
        }
34
        $this->logger->info(sprintf("Written %s STUB classes", count($items)));
35
    }
36
}
37