Completed
Push — master ( 163fd9...314ef3 )
by Neomerx
02:36
created

HasRequestFactoryTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setRequestFactory() 0 9 3
A isRequestFactorySet() 0 4 1
A getDefaultRequestFactory() 0 4 1
1
<?php namespace Limoncello\Core\Routing\Traits;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Core\Application\Application;
20
use LogicException;
21
22
/**
23
 * @package Limoncello\Core
24
 *
25
 * @method bool   isCallableToCache($value);
26
 * @method string getCallableToCacheMessage();
27
 */
28
trait HasRequestFactoryTrait
29
{
30
    /**
31
     * @var callable|false|null
32
     */
33
    private $requestFactory = false;
34
35
    /**
36
     * @param callable|null $requestFactory
37
     *
38
     * @return $this
39
     */
40 18
    public function setRequestFactory(callable $requestFactory = null)
41
    {
42 18
        if ($requestFactory !== null && $this->isCallableToCache($requestFactory) === false) {
43 2
            throw new LogicException($this->getCallableToCacheMessage());
44
        }
45 16
        $this->requestFactory = $requestFactory;
46
47 16
        return $this;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53 12
    protected function isRequestFactorySet()
54
    {
55 12
        return $this->requestFactory !== false;
56
    }
57
58
    /**
59
     * @return callable
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
60
     *
61
     * @SuppressWarnings(PHPMD.StaticAccess)
62
     */
63 5
    protected function getDefaultRequestFactory()
64
    {
65 5
        return Application::getDefaultRequestFactory();
66
    }
67
}
68