Synapse   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A __isset() 0 3 1
A getInstance() 0 3 1
A __set() 0 3 1
A __construct() 0 3 1
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 \Axiom\Rivescript\Rivescript  $rivescript
27
 * @property Memory                        $memory
28
 * @property Brain                         $brain
29
 * @property Input                         $input
30
 *
31
 * @category Core
32
 * @package  Cortext
33
 * @author   Shea Lewis <[email protected]>
34
 * @license  https://opensource.org/licenses/MIT MIT
35
 * @link     https://github.com/axiom-labs/rivescript-php
36
 * @since    0.3.0
37
 */
38
class Synapse
39
{
40
    /**
41
     * Object hash map.
42
     *
43
     * @var array[]
44
     */
45
    private array $map = [];
46
47
    /**
48
     * Static instance object.
49
     *
50
     * @var Synapse
51
     */
52
    public static Synapse $instance;
53
54
    /**
55
     * Construct a new Synapse instance.
56
     */
57
    public function __construct()
58
    {
59
        self::$instance = $this;
60
    }
61
62
    /**
63
     * Get the Synapse instance object.
64
     *
65
     * @return Synapse
66
     */
67
    public static function getInstance(): Synapse
68
    {
69
        return self::$instance;
70
    }
71
72
    /**
73
     * Magic __set method.
74
     *
75
     * @param string $key   The key to use to store $value.
76
     * @param mixed  $value The value to store.
77
     *
78
     * @return void
79
     */
80
    public function __set(string $key, $value): void
81
    {
82
        $this->map[$key] = $value;
83
    }
84
85
    /**
86
     * Check if a key has been set.
87
     *
88
     * @param string $key The key to use to store a value.
89
     *
90
     * @return bool
91
     */
92
    public function __isset(string $key): bool
93
    {
94
        return (isset($this->map[$key]) === true);
95
    }
96
97
    /**
98
     * Magic __get method.
99
     *
100
     * @param string $key The key to use to store a value.
101
     *
102
     * @return array
103
     */
104
    public function __get(string $key)
105
    {
106
        return $this->map[$key];
107
    }
108
}
109