Passed
Branch main (d5171d)
by Andreas
26:52 queued 08:26
created

FileChecker::checkPdfFileExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * FileChecker.
4
 *
5
 * @copyright 2014-2024 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Andreas Erhard <[email protected]>
7
 * @license LGPL-3.0-only
8
 * @link http://www.gerichtsmedizin.at/
9
 *
10
 * @package pdftk
11
 */
12
13
namespace Gmi\Toolkit\Pdftk\Util;
14
15
use Gmi\Toolkit\Pdftk\Exception\FileNotFoundException;
16
17
/**
18
 * Checks whether a file exists.
19
 */
20
class FileChecker
21
{
22
    /**
23
     * Checks whether a file exists.
24
     */
25 111
    public function checkFileExists(string $file, string $message = 'File "%s" not found!'): void
26
    {
27 111
        $exceptionMessage = (false !== strpos($message, '%s')) ? sprintf($message, $file) : $message;
28
29 111
        if (!file_exists($file)) {
30 10
            throw new FileNotFoundException($exceptionMessage);
31
        }
32 101
    }
33
34
    /**
35
     * Checks whether a PDF file exists.
36
     */
37 60
    public function checkPdfFileExists(string $file): void
38
    {
39 60
        $this->checkFileExists($file, 'PDF "%s" not found!');
40 52
    }
41
}
42