AssertDocumentThumbnailExtensionTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertDocumentThumbnailExtension() 0 13 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://tinyurl.com/vmbbh6kd for the canonical source repository
11
 * @license   https://tinyurl.com/3pc9am89
12
 * @copyright © 2023 Text Control GmbH
13
 */
14
15
namespace TextControl\ReportingCloud\Assert;
16
17
use TextControl\ReportingCloud\ReportingCloud;
18
19
/**
20
 * Trait AssertDocumentThumbnailExtensionTrait
21
 */
22
trait AssertDocumentThumbnailExtensionTrait
23
{
24
    use AssertOneOfTrait;
25
    use ValueToStringTrait;
26
27
    /**
28
     * Check value is a valid document thumbnail format extension
29
     *
30
     * This is a special case assert method that is used only by
31
     * TextControl\ReportingCloud\ReportingCloud::getDocumentThumbnails()
32
     * as this method additionally accepts files in XLSX format. No other methods do.
33
     */
34 8
    public static function assertDocumentThumbnailExtension(string $value, string $message = ''): void
35
    {
36 8
        $extension = pathinfo($value, PATHINFO_EXTENSION);
37 8
        $extension = strtoupper(/** @scrutinizer ignore-type */ $extension);
38
39 8
        $format  = '' === $message
40 6
            ? '%1$s contains an unsupported document thumbnail format file extension'
41 2
            : $message;
42 8
        $message = sprintf($format, self::valueToString($value));
43
44 8
        $fileFormats = [...ReportingCloud::FILE_FORMATS_DOCUMENT, ReportingCloud::FILE_FORMAT_XLSX];
45
46 8
        self::assertOneOf($extension, $fileFormats, $message);
47
    }
48
}
49