Passed
Push — develop ( 7909c1...ec92a4 )
by Johnny
07:21
created

Synapse::__isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of Rivescript-php
4
 *
5
 * (c) Shea Lewis <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Axiom\Rivescript\Cortex;
12
13
/**
14
 * Synapse class
15
 *
16
 * The Synapse is used in the brain as a storage
17
 * container for all kinds of information.
18
 *
19
 * PHP version 7.4 and higher.
20
 *
21
 * @property \Axiom\Collections\Collection $commands
22
 * @property \Axiom\Collections\Collection $triggers
23
 * @property \Axiom\Collections\Collection $tags
24
 * @property \Axiom\Collections\Collection $responses
25
 * @property \Axiom\Collections\Collection $conditions
26
 * @property Memory                        $memory
27
 * @property Brain                         $brain
28
 * @property Input                         $input
29
 *
30
 * @category Core
31
 * @package  Cortext
32
 * @author   Shea Lewis <[email protected]>
33
 * @license  https://opensource.org/licenses/MIT MIT
34
 * @link     https://github.com/axiom-labs/rivescript-php
35
 * @since    0.3.0
36
 */
37
class Synapse
38
{
39
    /**
40
     * Object hash map.
41
     *
42
     * @var array[]
43
     */
44
    private array $map = [];
45
46
    /**
47
     * Static instance object.
48
     *
49
     * @var Synapse
50
     */
51
    public static Synapse $instance;
52
53
    /**
54
     * Construct a new Synapse instance.
55
     */
56
    public function __construct()
57
    {
58
        self::$instance = $this;
59
    }
60
61
    /**
62
     * Get the Synapse instance object.
63
     *
64
     * @return Synapse
65
     */
66
    public static function getInstance(): Synapse
67
    {
68
        return self::$instance;
69
    }
70
71
    /**
72
     * Magic __set method.
73
     *
74
     * @param string $key   The key to use to store $value.
75
     * @param mixed  $value The value to store.
76
     *
77
     * @return void
78
     */
79
    public function __set(string $key, $value): void
80
    {
81
        $this->map[$key] = $value;
82
    }
83
84
    /**
85
     * Check if a key has been set.
86
     *
87
     * @param string $key The key to use to store a value.
88
     *
89
     * @return bool
90
     */
91
    public function __isset(string $key): bool
92
    {
93
        return (isset($this->map[$key]) === true);
94
    }
95
96
    /**
97
     * Magic __get method.
98
     *
99
     * @param string $key The key to use to store a value.
100
     *
101
     * @return array
102
     */
103
    public function __get(string $key)
104
    {
105
        return $this->map[$key];
106
    }
107
}
108