Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ValidatesExistence
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 validateExistence
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Hyde\Framework\Concerns;
4
5use Hyde\Framework\Exceptions\FileNotFoundException;
6use Hyde\Framework\Hyde;
7
8/**
9 * Validate the existence of a Page model's source file.
10 *
11 * @see \Tests\Unit\ValidatesExistenceTest
12 */
13trait ValidatesExistence
14{
15    /**
16     * Check if a supplied source file exists or throw an exception.
17     *
18     * @throws FileNotFoundException If the file does not exist.
19     */
20    public function validateExistence(string $model, string $slug): void
21    {
22        /** @var \Hyde\Framework\Contracts\AbstractPage $model */
23        $filepath = $model::$sourceDirectory.'/'.
24            $slug.$model::$fileExtension;
25
26        if (! file_exists(Hyde::path($filepath))) {
27            throw new FileNotFoundException($filepath);
28        }
29    }
30}