Code Duplication    Length = 21-21 lines in 4 locations

src/Parser/Lanyrd/ClosingDate.php 1 location

@@ 32-52 (lines=21) @@
29
 */
30
namespace Callingallpapers\Parser\Lanyrd;
31
32
class ClosingDate
33
{
34
    protected $timezone;
35
36
    public function __construct($timezone = 'UTC')
37
    {
38
        $this->timezone = new \DateTimezone($timezone);
39
    }
40
41
    public function parse($dom, $xpath)
42
    {
43
        $closingDate = $xpath->query("//span[text()='Closes on:']/following-sibling::strong");
44
        if (! $closingDate || $closingDate->length == 0) {
45
            throw new \InvalidArgumentException('The CfP does not seem to have a closing date');
46
        }
47
48
        $closingDate = $closingDate->item(0)->textContent;
49
50
        return new \DateTime($closingDate, $this->timezone);
51
    }
52
}
53

src/Parser/Lanyrd/EventEndDate.php 1 location

@@ 32-52 (lines=21) @@
29
 */
30
namespace Callingallpapers\Parser\Lanyrd;
31
32
class EventEndDate
33
{
34
    protected $timezone;
35
36
    public function __construct($timezone = 'UTC')
37
    {
38
        $this->timezone = new \DateTimezone($timezone);
39
    }
40
41
    public function parse($dom, $xpath)
42
    {
43
        $endDate = $xpath->query("//div[contains(@class, 'vevent')]/*/abbr[contains(@class, 'dtend')]"); ///a/abbr[class='dtstart']
44
        if (! $endDate || $endDate->length == 0) {
45
            throw new \InvalidArgumentException('The Event does not seem to have an end date');
46
        }
47
48
        $endDate = $endDate->item(0)->attributes->getNamedItem('title')->textContent;
49
50
        return new \DateTime($endDate, $this->timezone);
51
    }
52
}
53

src/Parser/Lanyrd/EventStartDate.php 1 location

@@ 32-52 (lines=21) @@
29
 */
30
namespace Callingallpapers\Parser\Lanyrd;
31
32
class EventStartDate
33
{
34
    protected $timezone;
35
36
    public function __construct($timezone = 'UTC')
37
    {
38
        $this->timezone = new \DateTimezone($timezone);
39
    }
40
41
    public function parse($dom, $xpath)
42
    {
43
        $startDate = $xpath->query("//div[contains(@class, 'vevent')]/*/abbr[contains(@class, 'dtstart')]"); ///a/abbr[class='dtstart']
44
        if (! $startDate || $startDate->length == 0) {
45
            throw new \InvalidArgumentException('The Event does not seem to have a start date');
46
        }
47
48
        $startDate = $startDate->item(0)->attributes->getNamedItem('title')->textContent;
49
50
        return new \DateTime($startDate, $this->timezone);
51
    }
52
}
53

src/Parser/Lanyrd/OpeningDate.php 1 location

@@ 32-52 (lines=21) @@
29
 */
30
namespace Callingallpapers\Parser\Lanyrd;
31
32
class OpeningDate
33
{
34
    protected $timezone;
35
36
    public function __construct($timezone = 'UTC')
37
    {
38
        $this->timezone = new \DateTimezone($timezone);
39
    }
40
41
    public function parse($dom, $xpath)
42
    {
43
        $openingDate = $xpath->query("//span[text()='Openend on:']/following-sibling::strong");
44
        if (! $openingDate || $openingDate->length == 0) {
45
            return new \DateTime();
46
        }
47
48
        $openingDate = $openingDate->item(0)->textContent;
49
50
        return new \DateTime($openingDate, $this->timezone);
51
    }
52
}
53