1 | <?php |
||
2 | |||
3 | namespace ByTIC\MFinante\Parsers; |
||
4 | |||
5 | use ByTIC\MFinante\Models\Company; |
||
6 | use DOMElement; |
||
7 | |||
8 | /** |
||
9 | * Class CompanyPage |
||
10 | * @package ByTIC\MFinante\Scrapers |
||
11 | */ |
||
12 | class CompanyPage extends AbstractParser |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @return array |
||
17 | */ |
||
18 | 1 | protected function generateContent() |
|
19 | { |
||
20 | 1 | $return = []; |
|
21 | 1 | $return['cif'] = $this->parseCif(); |
|
22 | 1 | $return = array_merge($return, $this->parseTable()); |
|
23 | 1 | $return['balance_sheets'] = $this->parseBalanceSheetsYears(); |
|
24 | 1 | return $return; |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * @inheritdoc |
||
29 | */ |
||
30 | public function getModelClassName() |
||
31 | { |
||
32 | return Company::class; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | 1 | protected function parseCif() |
|
39 | { |
||
40 | 1 | $html = $this->getCrawler()->filter('#main > div[align="center"] > b')->html(); |
|
41 | 1 | return trim(str_replace('AGENTUL ECONOMIC CU CODUL UNIC DE IDENTIFICARE', '', $html)); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | 1 | View Code Duplication | protected function parseTable() |
0 ignored issues
–
show
|
|||
48 | { |
||
49 | 1 | $table = $this->getCrawler()->filter('#main > center > table > tbody')->first(); |
|
50 | 1 | $rows = $table->children(); |
|
51 | 1 | $return = []; |
|
52 | 1 | foreach ($rows as $row) { |
|
53 | 1 | $rowParsed = $this->parseTableRow($row); |
|
54 | 1 | if ($rowParsed) { |
|
0 ignored issues
–
show
The expression
$rowParsed of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
55 | 1 | $return[$rowParsed[0]] = $rowParsed[1]; |
|
56 | } |
||
57 | } |
||
58 | 1 | return $return; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param DOMElement $row |
||
63 | * @return array |
||
64 | */ |
||
65 | 1 | View Code Duplication | protected function parseTableRow($row) |
0 ignored issues
–
show
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. ![]() |
|||
66 | { |
||
67 | 1 | $label = $row->childNodes[0]->nodeValue; |
|
68 | 1 | $label = str_replace(':', '', $label); |
|
69 | 1 | $label = str_replace('(*)', '', $label); |
|
70 | 1 | $label = str_replace('(**)', '', $label); |
|
71 | 1 | $label = str_replace("\n", ' ', $label); |
|
72 | 1 | $label = str_replace("\t", ' ', $label); |
|
73 | 1 | $label = preg_replace('/\s+/', ' ', $label); |
|
74 | 1 | $label = trim($label); |
|
75 | |||
76 | 1 | $value = str_replace("\n", ' ', $row->childNodes[2]->nodeValue); |
|
77 | 1 | $value = preg_replace('/\s+/', ' ', $value); |
|
78 | 1 | $value = trim($value); |
|
79 | |||
80 | 1 | $labels = self::getLabelMaps(); |
|
81 | |||
82 | 1 | $labelFind = array_search($label, $labels); |
|
83 | 1 | if ($labelFind) { |
|
84 | 1 | return [$labelFind, $value]; |
|
85 | } |
||
86 | return []; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | protected function parseBalanceSheetsYears() |
|
93 | { |
||
94 | 1 | $select = $this->getCrawler()->filter('form[name="codfiscalForm"] > select')->first(); |
|
95 | 1 | $options = $select->children(); |
|
96 | 1 | $years = []; |
|
97 | 1 | foreach ($options as $option) { |
|
98 | 1 | $years[] = $option->nodeValue; |
|
99 | } |
||
100 | 1 | return $years; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return array |
||
105 | */ |
||
106 | 1 | public static function getLabelMaps() |
|
107 | { |
||
108 | return [ |
||
109 | 1 | 'name' => 'Denumire platitor', |
|
110 | 'address' => 'Adresa', |
||
111 | 'county' => 'Judetul', |
||
112 | 'trade_register_code' => 'Numar de inmatriculare la Registrul Comertului', |
||
113 | 'authorization_code' => 'Act autorizare', |
||
114 | 'postal_code' => 'Codul postal', |
||
115 | 'phone' => 'Telefon', |
||
116 | 'fax' => 'Fax', |
||
117 | 'state' => 'Stare societate', |
||
118 | 'observations' => 'Observatii privind societatea comerciala', |
||
119 | 'date_last_statement' => 'Data inregistrarii ultimei declaratii', |
||
120 | 'date_last_processing' => 'Data ultimei prelucrari', |
||
121 | 'tax_profit' => 'Impozit pe profit (data luarii in evidenta)', |
||
122 | 'tax_income' => 'Impozit pe veniturile microintreprinderilor (data luarii in evidenta)', |
||
123 | 'tax_excise' => 'Accize (data luarii in evidenta)', |
||
124 | 'tax_vat' => 'Taxa pe valoarea adaugata (data luarii in evidenta)', |
||
125 | 'contribution_social' => 'Contributia de asigurari sociale (data luarii in evidenta)', |
||
126 | 'contribution_insurance' => 'Contributia de asigurare pentru accidente de munca si boli profesionale ' |
||
127 | . 'datorate de angajator (data luarii in evidenta)', |
||
128 | 'contribution_unemployment' => 'Contributia de asigurari pentru somaj (data luarii in evidenta)', |
||
129 | 'contribution_debts_fund' => 'Contributia angajatorilor pentru Fondul de garantare pentru plata creantelor' |
||
130 | . ' sociale (data luarii in evidenta)', |
||
131 | 'contribution_medical' => 'Contributia pentru asigurari de sanatate (data luarii in evidenta)', |
||
132 | 'contribution_leaves' => 'Contributii pentru concedii si indemnizatii de la persoane juridice sau fizice' |
||
133 | . ' (data luarii in evidenta)', |
||
134 | 'tax_gambling' => 'Taxa jocuri de noroc (data luarii in evidenta)', |
||
135 | 'tax_salaries' => 'Impozit pe veniturile din salarii si asimilate salariilor (data luarii in evidenta)', |
||
136 | 'tax_buildings' => 'Impozit pe constructii(data luarii in evidenta)', |
||
137 | 'tax_oil_gas' => 'Impozit la titeiul si la gazele naturale din productia interna (data luarii in evidenta)', |
||
138 | 'tax_mining' => 'Redevente miniere/Venituri din concesiuni si inchirieri (data luarii in evidenta)', |
||
139 | 'tax_oil' => 'Redevente petroliere (data luarii in evidenta)', |
||
140 | ]; |
||
141 | } |
||
142 | } |
||
143 |
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.