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

HasRequestFactoryTrait::getDefaultRequestFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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