Passed
Branch 6.0 (c154c1)
by Olivier
11:35
created

ResolvePathTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve_path() 0 11 3
1
<?php
2
3
namespace ICanBoogie\Render;
4
5
use function file_exists;
6
7
trait ResolvePathTrait
8
{
9
10
    /**
11
     * Resolves a template path.
12
     *
13
     * The method returns the pathname of the first file matching the path collection. The tried
14
     * paths are collected in `$tried`.
15
     *
16
     * @param string[] $tries Pathname collection, as returned by {@link resolve_tries()}.
17
     * @param string[] $tried Tried pathname collection.
18
     */
19
    private function resolve_path(array $tries, array &$tried): ?string
20
    {
21
        foreach ($tries as $pathname) {
22
            $tried[] = $pathname;
23
24
            if (file_exists($pathname)) {
25
                return $pathname;
26
            }
27
        }
28
29
        return null;
30
    }
31
}
32