Skip to content

Commit 4daa3be

Browse files
committed
removed unnecesary private methods
1 parent 1f403cc commit 4daa3be

File tree

2 files changed

+24
-62
lines changed

2 files changed

+24
-62
lines changed

src/SplitIO/Component/Common/Di.php

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class Di
1111
{
12-
private \SplitIO\Component\Log\Logger|null $logger = null;
12+
private \SplitIO\Component\Log\Logger $logger;
1313

1414
private int $factoryTracker = 0;
1515

@@ -62,91 +62,55 @@ public function __wakeup()
6262
{
6363
}
6464

65-
private function __trackFactory()
66-
{
67-
$this->factoryTracker += 1;
68-
return $this->factoryTracker;
69-
}
70-
71-
/**
72-
* @param \SplitIO\Component\Log\Logger $logger
73-
*/
74-
private function __setLogger(Logger $logger)
75-
{
76-
if (is_null($this->logger)) {
77-
$this->logger = $logger;
78-
return;
79-
}
80-
$this->logger->debug("logger was set before, ignoring new instance provided");
81-
}
82-
83-
/**
84-
* @return null|\SplitIO\Component\Log\Logger
85-
*/
86-
private function __getLogger()
87-
{
88-
return $this->logger;
89-
}
90-
91-
/**
92-
* @param string $ip
93-
*/
94-
private function __setIPAddress(string $ip)
95-
{
96-
if (empty($this->ipAddress)) {
97-
$this->ipAddress = $ip;
98-
return;
99-
}
100-
if (!(is_null($this->logger))) {
101-
$this->logger->debug("IPAddress was set before, ignoring new instance provided");
102-
}
103-
}
104-
105-
/**
106-
* @return null|string
107-
*/
108-
private function __getIPAddress()
109-
{
110-
return $this->ipAddress;
111-
}
112-
11365
/**
11466
* @return int
11567
*/
11668
public static function trackFactory()
11769
{
118-
return self::getInstance()->__trackFactory();
70+
self::getInstance()->factoryTracker += 1;
71+
return self::getInstance()->factoryTracker;
11972
}
12073

12174
/**
12275
* @param \SplitIO\Component\Log\Logger $logger
12376
*/
12477
public static function setLogger(Logger $logger)
12578
{
126-
self::getInstance()->__setLogger($logger);
79+
if (!isset(self::getInstance()->logger)) {
80+
self::getInstance()->logger = $logger;
81+
return;
82+
}
83+
self::getInstance()->logger->debug("logger was set before, ignoring new instance provided");
12784
}
12885

12986
/**
130-
* @return null|\SplitIO\Component\Log\Logger
87+
* @return \SplitIO\Component\Log\Logger
13188
*/
13289
public static function getLogger()
13390
{
134-
return self::getInstance()->__getLogger();
91+
if (!isset(self::getInstance()->logger)) {
92+
throw new Exception("logger was not set yet");
93+
}
94+
return self::getInstance()->logger;
13595
}
13696

13797
/**
13898
* @param string $ip
13999
*/
140100
public static function setIPAddress(string $ip)
141101
{
142-
self::getInstance()->__setIPAddress($ip);
102+
if (empty(self::getInstance()->ipAddress)) {
103+
self::getInstance()->ipAddress = $ip;
104+
return;
105+
}
106+
self::getInstance()->getLogger()->debug("IPAddress was set before, ignoring new instance provided");
143107
}
144108

145109
/**
146-
* @return null|string
110+
* @return string
147111
*/
148112
public static function getIPAddress()
149113
{
150-
return self::getInstance()->__getIPAddress();
114+
return self::getInstance()->ipAddress;
151115
}
152116
}

src/SplitIO/Sdk.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ public static function factory($apiKey = 'localhost', array $options = array())
3131
//Adding API Key into args array.
3232
$options['apiKey'] = $apiKey;
3333

34+
//Tracking Factory Instantiation
3435
self::registerInstance();
3536

36-
if ($apiKey == 'localhost') {
37-
//Register Logger
38-
self::registerLogger((isset($options['log'])) ? $options['log'] : array());
37+
//Register Logger
38+
self::registerLogger((isset($options['log'])) ? $options['log'] : array());
3939

40+
if ($apiKey == 'localhost') {
4041
return new LocalhostSplitFactory($options);
4142
} else {
42-
//Register Logger
43-
self::registerLogger((isset($options['log'])) ? $options['log'] : array());
44-
4543
//Register Cache
4644
$cache = self::configureCache((isset($options['cache'])) ? $options['cache'] : array());
4745

0 commit comments

Comments
 (0)