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

IntroductionDemo::testSerializable()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
c 1
b 0
f 0
rs 9.2
cc 4
eloc 12
nc 5
nop 0
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
/**
14
 * Example class to show how to dynamically add new interfaces and traits to the class
15
 */
16
class IntroductionDemo
17
{
18
19
    /**
20
     * Method that checks if the current instance implementing Serializable interface
21
     */
22
    public function testSerializable()
23
    {
24
        if ($this instanceof \Serializable) {
25
            echo get_class($this), ' implements `Serializable` interface now!', PHP_EOL;
26
            $reflection = new \ReflectionObject($this);
27
            echo "List of interfaces:", PHP_EOL;
28
            foreach ($reflection->getInterfaceNames() as $interfaceName) {
29
                echo '-> ', $interfaceName, PHP_EOL;
30
            }
31
            echo "List of traits:", PHP_EOL;
32
            foreach ($reflection->getTraitNames() as $traitName) {
33
                echo '-> ', $traitName, PHP_EOL;
34
            }
35
        } else {
36
            echo get_class($this), ' does not implement `Serializable` interface', PHP_EOL;
37
        }
38
    }
39
}
40