Passed
Push — master ( b500c8...f1f1b3 )
by Hirofumi
05:29
created

src/TemplateLoader.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Template;
5
6
use League\Flysystem\FileNotFoundException;
7
use League\Flysystem\Filesystem;
8
9
abstract class TemplateLoader
10
{
11
    /**
12
     * @var Filesystem
13
     */
14
    private $filesystem;
15
16
    /**
17
     * @param Filesystem $filesystem
18
     */
19 2
    public function __construct(Filesystem $filesystem)
20
    {
21 2
        $this->filesystem = $filesystem;
22 2
    }
23
24
    /**
25
     * @param string $templateName
26
     * @return Template
27
     * @throws TemplateNotFoundException
28
     */
29 2
    public function load(string $templateName): Template
30
    {
31
        try {
32 2
            $template = $this->filesystem->read($this->fileName($templateName));
33 1
        } catch (FileNotFoundException $e) {
34 1
            throw new TemplateNotFoundException($e->getPath());
35
        }
36
37 1
        return $this->template($template);
0 ignored issues
show
It seems like $template defined by $this->filesystem->read(...ileName($templateName)) on line 32 can also be of type false; however, Shippinno\Template\TemplateLoader::template() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
38
    }
39
40
    /**
41
     * @param string $templateName
42
     * @return string
43
     */
44
    abstract protected function fileName(string $templateName): string;
45
46
    /**
47
     * @param string $template
48
     * @return Template
49
     */
50
    abstract protected function template(string $template): Template;
51
}
52