Zurnal   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 17
dl 0
loc 60
c 0
b 0
f 0
rs 10
ccs 0
cts 22
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastChange() 0 8 2
A getAllChanges() 0 15 3
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt Žurnálu.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Žurnál změn
13
 * Journal of Changes
14
 *
15
 * @link https://demo.flexibee.eu/c/demo/adresar/properties položky evidence
16
 */
17
class Zurnal extends FlexiBeeRO
18
{
19
    /**
20
     * Evidence užitá objektem.
21
     *
22
     * @var string
23
     */
24
    public $evidence = 'zurnal';
25
26
    /**
27
     *
28
     * @var type
0 ignored issues
show
Bug introduced by
The type FlexiPeeHP\type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
     */
30
    public static $evidenceToDb = ['faktura-vydana' => 'ddoklfak'];
31
32
    /**
33
     * obtain all record changes array
34
     *
35
     * Note: Do not use this method in production environment!
36
     *
37
     *       If you have no other choice pleas add indexes into wzurnal
38
     *       postgesql table:
39
     *
40
     *       CREATE INDEX CONCURRENTLY tname_index ON wzurnal (tabulka);
41
     *       CREATE INDEX CONCURRENTLY rid_index ON wzurnal (idZaznamu);
42
     *
43
     * @param FlexiBeeRO $object
44
     * @return array changes history
45
     */
46
    public function getAllChanges($object)
47
    {
48
        $changesArray = [];
49
50
        $evidence = $object->getEvidence();
51
        if (array_key_exists($evidence, self::$evidenceToDb)) {
0 ignored issues
show
Bug introduced by
self::evidenceToDb of type FlexiPeeHP\type is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        if (array_key_exists($evidence, /** @scrutinizer ignore-type */ self::$evidenceToDb)) {
Loading history...
52
            $dbTable = self::$evidenceToDb[$evidence];
53
            $changes = $this->getColumnsFromFlexibee('*',
0 ignored issues
show
Bug introduced by
'*' of type string is incompatible with the type string[] expected by parameter $columnsList of FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            $changes = $this->getColumnsFromFlexibee(/** @scrutinizer ignore-type */ '*',
Loading history...
54
                ['tabulka' => $dbTable, 'idZaznamu' => $object->getMyKey()]);
55
56
            foreach ($changes as $change) {
57
                $changesArray[$change['datCas']][$change['sloupec']] = $change;
58
            }
59
        }
60
        return $changesArray;
61
    }
62
63
    /**
64
     * obtain last change array
65
     *
66
     * @param FlexiBeeRO $object
67
     * @return array Old/New values pairs
68
     */
69
    public function getLastChange($object)
70
    {
71
        $lastChange = null;
72
        $allChanges = $this->getAllChanges($object);
73
        if (count($allChanges)) {
74
            $lastChange = end($allChanges);
75
        }
76
        return $lastChange;
77
    }
78
}
79