Completed
Push — master ( 2fcc59...a319b9 )
by Joao
02:16
created
src/Singleton.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,31 +4,31 @@
 block discarded – undo
4 4
 
5 5
 trait Singleton
6 6
 {
7
-    protected function __construct()
8
-    {
9
-    }
7
+	protected function __construct()
8
+	{
9
+	}
10 10
 
11
-    /**
12
-     * @throws SingletonException
13
-     */
14
-    final public function __clone()
15
-    {
16
-        throw new SingletonException('You can not clone a singleton.');
17
-    }
11
+	/**
12
+	 * @throws SingletonException
13
+	 */
14
+	final public function __clone()
15
+	{
16
+		throw new SingletonException('You can not clone a singleton.');
17
+	}
18 18
 
19
-    /**
20
-     * @return static
21
-     */
22
-    public static function getInstance()
23
-    {
24
-        static $instances;
19
+	/**
20
+	 * @return static
21
+	 */
22
+	public static function getInstance()
23
+	{
24
+		static $instances;
25 25
 
26
-        $calledClass = get_called_class();
26
+		$calledClass = get_called_class();
27 27
 
28
-        if (!isset($instances[$calledClass])) {
29
-            $instances[$calledClass] = new $calledClass();
30
-        }
31
-        return $instances[$calledClass];
32
-    }
28
+		if (!isset($instances[$calledClass])) {
29
+			$instances[$calledClass] = new $calledClass();
30
+		}
31
+		return $instances[$calledClass];
32
+	}
33 33
 
34 34
 }
Please login to merge, or discard this patch.
tests/SingletonTest.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,43 +6,43 @@
 block discarded – undo
6 6
 
7 7
 class SingletonTest extends \PHPUnit\Framework\TestCase
8 8
 {
9
-    public function testSingleton()
10
-    {
11
-        $sample1 = Sample1::getInstance();
12
-        $this->assertEquals(10, $sample1->property);
13
-        $sample1->property = 20;
14
-        $this->assertEquals(20, $sample1->property);
15
-
16
-        $sample1Other = Sample1::getInstance();
17
-        $this->assertEquals(20, $sample1Other->property);
18
-        $sample1->property = 40;
19
-        $this->assertEquals(40, $sample1Other->property);
20
-        $this->assertEquals(40, $sample1->property);
21
-
22
-        //
23
-
24
-        $sample2 = Sample2::getInstance();
25
-        $sample2->property2 = 50;
26
-        $this->assertEquals(50, $sample2->property2);
27
-
28
-        $sample2Other = Sample2::getInstance();
29
-        $this->assertEquals(50, $sample2Other->property2);
30
-        $sample2->property2 = 90;
31
-        $this->assertEquals(90, $sample2Other->property2);
32
-        $this->assertEquals(90, $sample2->property2);
33
-
34
-        //
35
-
36
-        $this->assertEquals(40, $sample1->property);
37
-    }
38
-
39
-    /**
40
-     * @expectedException \ByJG\DesignPattern\SingletonException
41
-     */
42
-    public function testClone()
43
-    {
44
-        $sample1 = Sample1::getInstance();
45
-        $sample2 = clone $sample1;
46
-    }
9
+	public function testSingleton()
10
+	{
11
+		$sample1 = Sample1::getInstance();
12
+		$this->assertEquals(10, $sample1->property);
13
+		$sample1->property = 20;
14
+		$this->assertEquals(20, $sample1->property);
15
+
16
+		$sample1Other = Sample1::getInstance();
17
+		$this->assertEquals(20, $sample1Other->property);
18
+		$sample1->property = 40;
19
+		$this->assertEquals(40, $sample1Other->property);
20
+		$this->assertEquals(40, $sample1->property);
21
+
22
+		//
23
+
24
+		$sample2 = Sample2::getInstance();
25
+		$sample2->property2 = 50;
26
+		$this->assertEquals(50, $sample2->property2);
27
+
28
+		$sample2Other = Sample2::getInstance();
29
+		$this->assertEquals(50, $sample2Other->property2);
30
+		$sample2->property2 = 90;
31
+		$this->assertEquals(90, $sample2Other->property2);
32
+		$this->assertEquals(90, $sample2->property2);
33
+
34
+		//
35
+
36
+		$this->assertEquals(40, $sample1->property);
37
+	}
38
+
39
+	/**
40
+	 * @expectedException \ByJG\DesignPattern\SingletonException
41
+	 */
42
+	public function testClone()
43
+	{
44
+		$sample1 = Sample1::getInstance();
45
+		$sample2 = clone $sample1;
46
+	}
47 47
 
48 48
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/../vendor/autoload.php";
3
+require_once __DIR__."/../vendor/autoload.php";
4 4
 require_once "Sample1.php";
5 5
 require_once "Sample2.php";
6 6
 
Please login to merge, or discard this patch.
tests/Sample1.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@
 block discarded – undo
4 4
 
5 5
 class Sample1
6 6
 {
7
-    use \ByJG\DesignPattern\Singleton;
7
+	use \ByJG\DesignPattern\Singleton;
8 8
 
9
-    public $property;
9
+	public $property;
10 10
 
11
-    private function __construct()
12
-    {
13
-        $this->property = 10;
14
-    }
11
+	private function __construct()
12
+	{
13
+		$this->property = 10;
14
+	}
15 15
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/../vendor/autoload.php";
3
+require_once __DIR__."/../vendor/autoload.php";
4 4
 
5 5
 class Sample1
6 6
 {
Please login to merge, or discard this patch.
tests/Sample2.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 class Sample2
6 6
 {
7
-    use \ByJG\DesignPattern\Singleton;
7
+	use \ByJG\DesignPattern\Singleton;
8 8
 
9
-    public $property2;
9
+	public $property2;
10 10
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . "/../vendor/autoload.php";
3
+require_once __DIR__."/../vendor/autoload.php";
4 4
 
5 5
 class Sample2
6 6
 {
Please login to merge, or discard this patch.