JusticeSpolecnikPersonParser   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 95.24 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 0
cbo 4
dl 20
loc 21
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseFromDomCrawler() 13 13 1

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
3
namespace Defr\Parser;
4
5
use Defr\Parser\Helper\StringHelper;
6
use Defr\ValueObject\Person;
7
use Symfony\Component\DomCrawler\Crawler;
8
9 View Code Duplication
final class JusticeSpolecnikPersonParser
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    /**
12
     * @param Crawler $crawler
13
     *
14
     * @return Person
15
     */
16
    public static function parseFromDomCrawler(Crawler $crawler)
17
    {
18
        $content = $crawler->text();
19
        $content = StringHelper::removeEmptyLines($content);
20
21
        $contentItems = explode("\n", $content);
22
        $contentItems = array_map('trim', $contentItems);
23
        $name = trim(explode(',', $contentItems[1])[0]);
24
25
        $birthday = DateTimeParser::parseFromCzechDateString($contentItems[2]);
26
27
        return new Person($name, $birthday, $contentItems[3]);
0 ignored issues
show
Documentation introduced by
$birthday is of type object<DateTime>, but the function expects a object<DateTimeInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
    }
29
}
30