Completed
Push — master ( 70fc1a...2d4410 )
by Michael
02:52
created

ActivationStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Contains class ActivationStrategy.
4
 *
5
 * PHP version 5.5
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\Log;
35
36
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
37
use Monolog\Logger;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Yapeal\Log\Logger.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
38
39
/**
40
 * Class ActivationStrategy.
41
 *
42
 * A runtime instead of just new instance settable error level activation strategy like what is include with Monolog.
43
 */
44
class ActivationStrategy implements ActivationStrategyInterface
45
{
46
    /**
47
     * ActivationStrategy constructor.
48
     *
49
     * @param $actionLevel
50
     */
51
    public function __construct($actionLevel)
52
    {
53
        $this->actionLevel = Logger::toMonologLevel($actionLevel);
54
    }
55
    /**
56
     * @param array $record
57
     *
58
     * @return bool
59
     */
60
    public function isHandlerActivated(array $record)
61
    {
62
        return $record['level'] >= $this->actionLevel;
63
    }
64
    public function setActionLevel($value)
65
    {
66
        $this->actionLevel = Logger::toMonologLevel($value);
67
    }
68
    /**
69
     * @var int $actionLevel
70
     */
71
    private $actionLevel;
72
}
73