Completed
Pull Request — master (#37)
by Andreas
01:34
created

ClosingDate::clearClosingHour()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
namespace Callingallpapers\Subcommands\Sessionize\Parser;
11
12
use DateTimeImmutable;
13
use DateTimeZone;
14
use DOMDocument;
15
use DOMXPath;
16
use InvalidArgumentException;
17
use function str_replace;
18
use function trim;
19
20
class ClosingDate
21
{
22
    protected $timezone;
23
24
    public function __construct(DateTimeZone $timezone)
25
    {
26
        $this->timezone = $timezone;
27
    }
28
29 View Code Duplication
    public function parse(DOMDocument $dom, DOMXPath $xpath) : DateTimeImmutable
0 ignored issues
show
Unused Code introduced by
The parameter $dom is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
30
    {
31
        $closingDateHolder = $xpath->query('//div[./div/span[contains(text(), "CfS closes at")]]');
32
33
        if (! $closingDateHolder || $closingDateHolder->length == 0) {
34
            throw new InvalidArgumentException('The CfP does not seem to have a closing date');
35
        }
36
37
        $closingDay = $closingDateHolder->item(0)->getElementsByTagName('h2')->item(0)->textContent;
38
        $closingHour = $closingDateHolder->item(0)->getElementsByTagName('span')->item(0)->textContent;
39
40
        $closingHour = $this->clearClosingHour($closingHour);
41
42
        return new DateTimeImmutable($closingDay . ' ' . $closingHour, $this->timezone);
43
    }
44
45
    private function clearClosingHour(string $closingHour) : string
46
    {
47
        return trim(str_replace('CfS closes at', '', $closingHour));
48
    }
49
}
50