Completed
Push — master ( d404ac...fc4cfb )
by Alexander
10:24 queued 07:21
created

LoggingDemo::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Demo\Example;
12
13
use Demo\Annotation\Loggable;
14
15
/**
16
 * Example class to show how to use logging with AOP
17
 */
18
class LoggingDemo
19
{
20
21
    /**
22
     * Executes a task and logs all incoming arguments
23
     *
24
     * @Loggable
25
     * @param mixed $task Some specific argument
26
     */
27
    public function execute($task)
28
    {
29
        $this->perform($task, 'first');
30
        $this->perform($task, 'second');
31
    }
32
33
    /**
34
     * Protected method can be also loggable
35
     *
36
     * @Loggable
37
     *
38
     * @param mixed $task Specific task
39
     * @param string $level
40
     */
41
    protected function perform($task, $level)
42
    {
43
        // some logic here
44
    }
45
46
    /**
47
     * Everything is possible with AOP, so static methods can be intercepted too
48
     *
49
     * @Loggable
50
     *
51
     * @param string $task Some specific argument
52
     */
53
    public static function runByName($task)
54
    {
55
        $instance = new static(); // Go! AOP requires LSB to work correctly
56
        $instance->execute($task);
57
    }
58
}
59