BalanceSheetPage::generateCrawler()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.1574

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 14
cp 0.7856
rs 9.2
c 0
b 0
f 0
cc 4
eloc 14
nc 1
nop 0
crap 4.1574
1
<?php
2
3
namespace ByTIC\MFinante\Scrapers;
4
5
use ByTIC\MFinante\Exception\InvalidArgumentException;
6
use ByTIC\MFinante\Exception\InvalidCifException;
7
use ByTIC\MFinante\Helper;
8
use ByTIC\MFinante\Parsers\BalanceSheetPage as Parser;
9
10
/**
11
 * Class BalanceSheetPage
12
 * @package ByTIC\MFinante\Scrapers
13
 *
14
 * @method Parser execute()
15
 */
16
class BalanceSheetPage extends AbstractScraper
17
{
18
    /**
19
     * @var int
20
     */
21
    protected $cif;
22
23
    /**
24
     * @var int
25
     */
26
    protected $year;
27
28
    /**
29
     * CompanyPage constructor.
30
     * @param int $cif
31
     * @param int $year
32
     */
33 2
    public function __construct($cif, $year)
34
    {
35 2
        $this->setCif($cif);
36 2
        $this->setYear($year);
37 2
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 1
    protected function generateCrawler()
43
    {
44 1
        if (!Helper::validateCif($this->getCif())) {
45
            throw new InvalidCifException();
46
        }
47 1
        $year = intval($this->getYear());
48 1
        if ($year < 2000 or $year > date('Y')) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
49
            throw new InvalidArgumentException(
50
                'Year [' . $this->getYear() . '] is invalid'
51
            );
52
        }
53 1
        $crawler = $this->getClient()->request(
54 1
            'GET',
55
            'http://www.mfinante.gov.ro/infocodfiscal.html?' .
56 1
            'an=WEB_ONG_AN' . $year
57 1
            . '&cod=' . $this->getCif()
58 1
            . '&captcha=null'
59 1
            . '&method.bilant=VIZUALIZARE'
60
        );
61 1
        return $crawler;
62
    }
63
64
    /**
65
     * @return int
66
     */
67 1
    public function getCif()
68
    {
69 1
        return $this->cif;
70
    }
71
72
    /**
73
     * @param int $cif
74
     */
75 2
    public function setCif($cif)
76
    {
77 2
        $this->cif = $cif;
78 2
    }
79
80
    /**
81
     * @return int
82
     */
83 2
    public function getYear(): int
84
    {
85 2
        return $this->year;
86
    }
87
88
    /**
89
     * @param int $year
90
     */
91 2
    public function setYear(int $year)
92
    {
93 2
        $this->year = $year;
94 2
    }
95
}
96