Passed
Branch master (3d4f7a)
by Matteo
03:42
created
src/Cache.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
      * The path where to save the cached things
14 14
      */
15 15
     private $path;
16
-	// Length of time to cache a file (in seconds)
17
-	public $ttl;
16
+    // Length of time to cache a file (in seconds)
17
+    public $ttl;
18 18
 
19 19
     public function __construct(string $path = null, int $ttl = 3600 * 24 * 1)
20 20
     {
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
         $this->ttl = $ttl ?? getenv("CACHE_TTL");
23 23
     }
24 24
 
25
-	/**
25
+    /**
26 26
      * This methods tries to hit the cache and if the content is not present
27 27
      * or expired caches it for future usage
28 28
      * 
29 29
      * @param   string  $label  The key of the resource to cache
30 30
      * @param   StringProvider  $provider   The provider for the actual content
31 31
      */
32
-	public function getString(string $label, StringProvider $provider = null) : string
33
-	{
32
+    public function getString(string $label, StringProvider $provider = null) : string
33
+    {
34 34
         try {
35 35
             return $this->hitString($label);
36 36
         } catch (NotCachedException $e) {
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
      * @param   string  $label  The key of the resource to cache
51 51
      * @param   JsonProvider  $provider   The provider for the actual content
52 52
      */
53
-	public function getJson(string $label, JsonProvider $provider = null) : array
54
-	{
53
+    public function getJson(string $label, JsonProvider $provider = null) : array
54
+    {
55 55
         try {
56 56
             return json_decode($this->hitString($label), true);
57 57
         } catch (NotCachedException $e) {
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
      * @param   string  $label  The key of the resource to cache
71 71
      * @param   string  $data   The actual content of the resource to cache
72 72
      */
73
-	public function cacheString(string $label, string $data) : void
74
-	{
73
+    public function cacheString(string $label, string $data) : void
74
+    {
75 75
         $filename = $this->path . "/" . md5($label);
76 76
         if (file_exists($filename) && is_file($filename)) {
77 77
             unlink($filename);
78 78
         }
79
-		file_put_contents($filename, $data);
79
+        file_put_contents($filename, $data);
80 80
     }
81 81
 
82 82
     /**
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
      * @param   string  $label  The key of the resource to cache
86 86
      * @param   array  $data   The actual content of the resource to cache
87 87
      */
88
-	public function cacheJson(string $label, array $data) : void
89
-	{
88
+    public function cacheJson(string $label, array $data) : void
89
+    {
90 90
         $this->cacheString($label, json_encode($data));
91 91
     }
92 92
     
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
      * 
100 100
      * @return  string  The content of the cached resource
101 101
      */
102
-	public function hitString(string $label) : string
103
-	{
104
-		if($this->isCached($label)){
105
-			$filename = $this->path . "/" . md5($label);
106
-			return file_get_contents($filename);
107
-		} else {
102
+    public function hitString(string $label) : string
103
+    {
104
+        if($this->isCached($label)){
105
+            $filename = $this->path . "/" . md5($label);
106
+            return file_get_contents($filename);
107
+        } else {
108 108
             throw new NotCachedException($label);
109 109
         }
110 110
     }
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
      * 
119 119
      * @return  array  The content of the cached resource
120 120
      */
121
-	public function hitJson(string $label) : array
122
-	{
123
-		return json_decode($this->hitString($label), true);
121
+    public function hitJson(string $label) : array
122
+    {
123
+        return json_decode($this->hitString($label), true);
124 124
     }
125 125
     
126 126
     /**
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
      * 
131 131
      * @return  bool    Whether the $label resource is cached
132 132
      */
133
-	public function isCached(string $label) : bool
134
-	{
135
-		$filename = $this->path . "/" . md5($label);
133
+    public function isCached(string $label) : bool
134
+    {
135
+        $filename = $this->path . "/" . md5($label);
136 136
         if(file_exists($filename) && (filemtime($filename) + $this->ttl >= time())) {
137 137
             return true;
138 138
         }
139
-		return false;
139
+        return false;
140 140
     }
141 141
     
142 142
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Cacheasy;
5 5
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
 	public function hitString(string $label) : string
103 103
 	{
104
-		if($this->isCached($label)){
104
+		if ($this->isCached($label)) {
105 105
 			$filename = $this->path . "/" . md5($label);
106 106
 			return file_get_contents($filename);
107 107
 		} else {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	public function isCached(string $label) : bool
134 134
 	{
135 135
 		$filename = $this->path . "/" . md5($label);
136
-        if(file_exists($filename) && (filemtime($filename) + $this->ttl >= time())) {
136
+        if (file_exists($filename) && (filemtime($filename) + $this->ttl >= time())) {
137 137
             return true;
138 138
         }
139 139
 		return false;
Please login to merge, or discard this patch.
src/StringProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Cacheasy;
5 5
 
Please login to merge, or discard this patch.
src/NotCachedException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Cacheasy;
5 5
 
Please login to merge, or discard this patch.
src/JsonProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Cacheasy;
5 5
 
Please login to merge, or discard this patch.