Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ParserUrl
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parseValue
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 setMsgContent
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
4 */
5
6declare(strict_types=1);
7
8namespace pvc\parser\url;
9
10use pvc\interfaces\http\UrlInterface;
11use pvc\interfaces\msg\MsgInterface;
12use pvc\parser\Parser;
13
14/**
15 * Class UrlParser
16 * @extends Parser<UrlInterface>
17 */
18class ParserUrl extends Parser
19{
20    protected UrlInterface $url;
21
22    public function __construct(MsgInterface $msg, UrlInterface $url)
23    {
24        parent::__construct($msg);
25        $this->url = $url;
26    }
27
28    public function getUrl(): UrlInterface
29    {
30        return $this->url;
31    }
32
33    public function setUrl(UrlInterface $url): void
34    {
35        $this->url = $url;
36    }
37
38    /**
39     * parseValue
40     * @param string $data
41     * @return bool
42     */
43    public function parseValue(string $data): bool
44    {
45        $parsedResult = parse_url($data);
46
47        if (false === $parsedResult) {
48            return false;
49        } else {
50            $this->url->setAttributesFromArray($parsedResult);
51            $this->parsedValue = $this->url;
52            return true;
53        }
54    }
55
56    /**
57     * setMsgContent
58     * @param MsgInterface $msg
59     */
60    protected function setMsgContent(MsgInterface $msg): void
61    {
62        $msgId = 'invalid_url';
63        $msgParameters = [];
64        $msg->setContent($this->getMsgDomain(), $msgId, $msgParameters);
65    }
66}