Passed
Branch development-2.0 (f1893c)
by Jonathan
06:14
created

assertDocumentDivider()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
ccs 11
cts 12
cp 0.9167
rs 9.5555
c 0
b 0
f 0
cc 5
nc 12
nop 2
crap 5.0144
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP Wrapper
6
 *
7
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
8
 *
9
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
10
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
11
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
12
 * @copyright © 2019 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Assert;
16
17
use ReflectionClass;
18
use ReflectionException;
19
use TxTextControl\ReportingCloud\ReportingCloud;
20
21
/**
22
 * Trait DocumentDividerTrait
23
 *
24
 * @package TxTextControl\ReportingCloud
25
 */
26
trait AssertDocumentDividerTrait
27
{
28 4
    public static function assertDocumentDivider(int $value, string $message = '')
29
    {
30 4
        $haystack = [];
31
        try {
32 4
            $reportingCloud  = new ReportingCloud();
33 4
            $reflectionClass = new ReflectionClass($reportingCloud);
34 4
            foreach ($reflectionClass->getConstants() as $constantKey => $constantValue) {
35 4
                if (0 === strpos($constantKey, 'DOCUMENT_DIVIDER_')) {
36 4
                    $haystack[] = $constantValue;
37
                }
38
            }
39 4
            unset($reportingCloud);
40
        } catch (ReflectionException $e) {
41
            // continue
42
        }
43
44 4
        $format  = '%s contains an unsupported document divider';
45 4
        $message = sprintf($message ?: $format, static::valueToString($value));
46
47 4
        return static::oneOf($value, $haystack, $message);
48
    }
49
}
50