Test Failed
Push — feature/pdfcpu ( 859fd3...f782de )
by Andreas
13:47
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!')
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)
38
    {
39
        return $this->checkFileExists($file, 'PDF "%s" not found!');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->checkFileExists($... 'PDF "%s" not found!') targeting Gmi\Toolkit\Pdftk\Util\F...cker::checkFileExists() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
    }
41
}
42