Test Failed
Push — main ( 961615...d5171d )
by Andreas
12:44 queued 13s
created

FileChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkPdfFileExists() 0 3 1
A checkFileExists() 0 6 3
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
    public function checkFileExists(string $file, string $message = 'File "%s" not found!'): void
26
    {
27
        $exceptionMessage = (false !== strpos($message, '%s')) ? sprintf($message, $file) : $message;
28
29
        if (!file_exists($file)) {
30
            throw new FileNotFoundException($exceptionMessage);
31
        }
32
    }
33
34
    /**
35
     * Checks whether a PDF file exists.
36
     */
37
    public function checkPdfFileExists(string $file): void
38
    {
39
        $this->checkFileExists($file, 'PDF "%s" not found!');
40
    }
41
}
42