BuildRouteTrait::buildRoute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace TomHart\Routing\Traits;
4
5
use InvalidArgumentException;
6
7
trait BuildRouteTrait
8
{
9
    /**
10
     * Builds a route, providing a routeName property exists on the class.
11
     *
12
     * @param mixed[] $data Static data to be passed.
13
     *
14
     * @return string
15
     */
16
    public function buildRoute(array $data = []): string
17
    {
18
        if (!property_exists($this, 'routeName')) {
19
            throw new InvalidArgumentException(BuildRouteTrait::class.' requires a "routeName" property');
20
        }
21
22
        return route_from_model($this->routeName, $this, $data);
23
    }
24
}
25