RelatedEntity   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 48
ccs 9
cts 16
cp 0.5625
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 4
1
<?php
2
/**
3
 * MOJEPANSTWO-API
4
 *
5
 * Copyright © 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
/**
16
 * Created by Marcin.
17
 * Date: 02.12.2017
18
 * Time: 23:19
19
 */
20
21
namespace mrcnpdlk\MojePanstwo\Model\KrsPerson;
22
23
24
use mrcnpdlk\MojePanstwo\Api;
25
use Sunra\PhpSimple\HtmlDomParser;
26
27
class RelatedEntity
28
{
29
    /**
30
     * @var string
31
     */
32
    public $opis;
33
    /**
34
     * ID podmiotu KRS
35
     *
36
     * @var int
37
     */
38
    public $podmiot_id;
39
    /**
40
     * @var null|\mrcnpdlk\MojePanstwo\Model\KrsEntity
41
     */
42
    public $podmiot;
43
44
    /**
45
     * RelatedEntity constructor.
46
     *
47
     * @param string $str
48
     *
49
     * @throws \mrcnpdlk\MojePanstwo\Exception
50
     */
51 1
    public function __construct(string $str)
52
    {
53 1
        $this->opis = strip_tags($str);
54
        try {
55 1
            $aElem = HtmlDomParser::str_get_html($str)->getElementByTagName('a');
56 1
            if ($aElem) {
57 1
                $sHref = $aElem->getAttribute('href');
58 1
                $id    = (int)str_replace('/dane/krs_podmioty/', '', $sHref);
59 1
                if ($id > 0) {
60 1
                    $this->podmiot_id = $id;
61
                } else {
62
                    throw new \RuntimeException('KRS id not found in href');
63
                }
64
            }
65
        } catch (\Exception $e) {
66
            $this->podmiot_id = null;
67
            Api::getInstance()
68
               ->getClient()
69
               ->getLogger()
70
               ->warning(sprintf('Related entity [%s] Error: %s', $str, $e->getMessage()))
71
            ;
72
        }
73 1
    }
74
}
75