assertDocumentThumbnailExtension()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 9.9332
cc 2
nc 2
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP SDK
6
 *
7
 * PHP SDK 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://git.io/Jejj2 for the canonical source repository
11
 * @license   https://git.io/Jejjr
12
 * @copyright © 2022 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Assert;
16
17
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException;
18
use TxTextControl\ReportingCloud\ReportingCloud;
19
20
/**
21
 * Trait AssertDocumentThumbnailExtensionTrait
22
 *
23
 * @package TxTextControl\ReportingCloud
24
 * @author  Jonathan Maron (@JonathanMaron)
25
 */
26
trait AssertDocumentThumbnailExtensionTrait
27
{
28
    use ValueToStringTrait;
29
    use AssertOneOfTrait;
30
31
    /**
32
     * Check value is a valid document thumbnail format extension
33
     *
34
     * This is a special case assert method that is used only by
35
     * TxTextControl\ReportingCloud\ReportingCloud::getDocumentThumbnails()
36
     * as this method additionally accepts files in XLSX format. No other methods do.
37
     *
38
     * @param string $value
39
     * @param string $message
40
     *
41
     * @return void
42
     * @throws InvalidArgumentException
43
     */
44 8
    public static function assertDocumentThumbnailExtension(string $value, string $message = ''): void
45
    {
46 8
        $extension = pathinfo($value, PATHINFO_EXTENSION);
47 8
        $extension = strtoupper(/** @scrutinizer ignore-type */ $extension);
48
49 8
        $format  = 0 === strlen($message)
50 6
            ? '%1$s contains an unsupported document thumbnail format file extension'
51 2
            : $message;
52 8
        $message = sprintf($format, self::valueToString($value));
53
54 8
        $fileFormats = array_merge(
55 8
            ReportingCloud::FILE_FORMATS_DOCUMENT,
56 8
            [
57 8
                ReportingCloud::FILE_FORMAT_XLSX
58 8
            ]
59 8
        );
60
61 8
        self::assertOneOf($extension, $fileFormats, $message);
62
    }
63
}
64