Passed
Pull Request — master (#11)
by Victor
02:42
created

HasDataTrait::hasData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Utilities;
5
6
use Shoot\Shoot\PresentationModel;
7
8
/**
9
 * A convenience trait for Presenters. It checks if a presentation model already holds data. If so, it might not be
10
 * necessary to perform any action on it.
11
 */
12
trait HasDataTrait
13
{
14
    /**
15
     * Returns whether the presentation model already holds data.
16
     *
17
     * @param PresentationModel $presentationModel
18
     *
19
     * @return bool
20
     */
21
    private function hasData(PresentationModel $presentationModel): bool
22
    {
23
        foreach ($presentationModel->getVariables() as $value) {
24
            if (!empty($value)) {
25
                return true;
26
            }
27
        }
28
29
        return false;
30
    }
31
}
32