Test Failed
Push — master ( dba518...111789 )
by Vítězslav
04:17
created

UcetniObdobi::createYearsFrom()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
nc 6
nop 2
dl 0
loc 22
rs 8.9197
c 1
b 0
f 0
ccs 14
cts 14
cp 1
crap 4
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt účetního období.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Class for Accounting period handling.
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/ucetni-obdobi/properties Položky evidence
15
 * @author vitex
16
 */
17
class UcetniObdobi extends FlexiBeeRW
18
{
19
    /**
20
     * Evidence FlexiBee
21
     * @var string
22
     */
23
    public $evidence = 'ucetni-obdobi';
24
25
    /**
26
     * Create requested Accounting period
27
     *
28
     * @param int $startYear first year to create
29
     * @param int $endYear   last yar to create - default is current year
30
     *
31
     * @return array Results
32
     */
33 1
    public function createYearsFrom($startYear, $endYear = null)
34
    {
35 1
        $result = [];
36 1
        if (is_null($endYear)) {
37 1
            $endYear = date('Y');
38
        }
39 1
40 1
        for ($year = $startYear; $year <= $endYear; ++$year) {
41 1
            $obdobi = ['kod' => $year,
42 1
                'platiOdData' => $year.'-01-01T00:00:00',
43 1
                'platiDoData' => $year.'-12-31T23:59:59',
44 1
            ];
45 1
            if ($this->idExists('code:'.$year)) {
46 1
                $this->addStatusMessage(sprintf(_('%s already exists.'), $year));
47 1
            } else {
48 1
                $this->setData($obdobi);
49
                $result[] = $this->insertToFlexibee();
50
            $this->dataReset();
51
        }
52
        }
53
        return $result;
54
    }
55
}
56