Passed
Push — master ( 8b0281...9e9f0c )
by Anthony
02:44
created
Service/Version.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -15,179 +15,179 @@
 block discarded – undo
15 15
 
16 16
 class Version
17 17
 {
18
-    /**
19
-     * @var EntityManagerInterface
20
-     */
21
-    private $em;
22
-
23
-    /**
24
-     * @var HttpClientInterface
25
-     */
26
-    private $client;
27
-
28
-    /**
29
-     * @var ParameterBagInterface
30
-     */
31
-    private $parameter;
32
-
33
-    /**
34
-     * @var PackagistApi
35
-     */
36
-    private $packagist;
37
-
38
-    /**
39
-     * @var mixed
40
-     */
41
-    private $local_token;
42
-
43
-    /**
44
-     * @var Package
45
-     */
46
-    private $package;
47
-
48
-    private $messages = [];
49
-
50
-    /**
51
-     * Version constructor.
52
-     * @param EntityManagerInterface $em
53
-     * @param HttpClientInterface $client
54
-     * @param ParameterBagInterface $parameter
55
-     * @param PackagistApi $packagist
56
-     */
57
-    public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist)
58
-    {
59
-        $this->em = $em;
60
-        $this->client = $client;
61
-        $this->parameter = $parameter;
62
-        $this->packagist = $packagist;
63
-        $this->local_token = $parameter->get("ribs_admin.packages_token");
64
-    }
65
-
66
-    /**
67
-     * @return array
68
-     */
69
-    public function getMessages(): array
70
-    {
71
-        return $this->messages;
72
-    }
73
-
74
-    /**
75
-     * @param Package $package
76
-     */
77
-    public function setPackageEntity(Package $package) {
78
-        $this->package = $package;
79
-    }
80
-
81
-    /**
82
-     * @return mixed|null
83
-     */
84
-    private function getToken()
85
-    {
86
-        $token = null;
87
-        $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/");
88
-        $datas = $response->getStatusCode() == 200 ? $response->getContent() : null;
89
-
90
-        if ($datas) {
91
-            $token = json_decode($datas, true)["token"];
92
-        }
93
-
94
-        return $token;
95
-    }
96
-
97
-    /**
98
-     * @return mixed|null
99
-     * @throws ClientExceptionInterface
100
-     * @throws RedirectionExceptionInterface
101
-     * @throws ServerExceptionInterface
102
-     * @throws TransportExceptionInterface
103
-     */
104
-    private function getComposerLockJson()
105
-    {
106
-        if ($this->package && !$this->package->isIsLocal()) {
107
-            $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl());
108
-            $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
109
-        } else {
110
-            $composer_lock = file_get_contents('../composer.lock');
111
-        }
112
-
113
-        if ($composer_lock) {
114
-            return json_decode($composer_lock, true);
115
-        }
116
-
117
-        return null;
118
-    }
119
-
120
-    /**
121
-     * @return mixed|null
122
-     * @throws ClientExceptionInterface
123
-     * @throws RedirectionExceptionInterface
124
-     * @throws ServerExceptionInterface
125
-     * @throws TransportExceptionInterface
126
-     */
127
-    public function getPackage()
128
-    {
129
-        $composer_lock = $this->getComposerLockJson();
130
-        if ($composer_lock) {
131
-            $packages = $composer_lock["packages"];
132
-            $key = array_search($this->package->getPackageName(), array_column($packages, 'name'));
133
-
134
-            if ($key) {
135
-                return $packages[$key];
136
-            }
137
-        }
138
-
139
-        $this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl();
140
-
141
-        return null;
142
-    }
143
-
144
-    /**
145
-     * @return mixed|null
146
-     */
147
-    public function getVersion()
148
-    {
149
-        return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null;
150
-    }
151
-
152
-    /**
153
-     * @return DateTime|null
154
-     * @throws Exception
155
-     */
156
-    public function getVersionDate(): ?DateTime
157
-    {
158
-        $string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null;
159
-        $version_date = null;
160
-
161
-        if ($string_date) {
162
-            $version_date = new DateTime($string_date);
163
-        }
164
-
165
-        return $version_date;
166
-    }
167
-
168
-    /**
169
-     * @param $package_guid
170
-     * @throws Exception
171
-     */
172
-    public function save($package_guid)
173
-    {
174
-        $package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]);
175
-
176
-        if ($package) {
177
-            $this->setPackageEntity($package);
178
-
179
-            if (!$this->getToken() || $this->getToken() !== $this->local_token) {
180
-                $this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl();
181
-                return;
182
-            }
183
-
184
-            $package->setVersion($this->getVersion());
185
-            $package->setVersionDate($this->getVersionDate());
186
-            $package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName()));
187
-            $package->setLastCheck(new DateTime());
188
-
189
-            $this->em->persist($package);
190
-            $this->em->flush();
191
-        }
192
-    }
18
+				/**
19
+				 * @var EntityManagerInterface
20
+				 */
21
+				private $em;
22
+
23
+				/**
24
+				 * @var HttpClientInterface
25
+				 */
26
+				private $client;
27
+
28
+				/**
29
+				 * @var ParameterBagInterface
30
+				 */
31
+				private $parameter;
32
+
33
+				/**
34
+				 * @var PackagistApi
35
+				 */
36
+				private $packagist;
37
+
38
+				/**
39
+				 * @var mixed
40
+				 */
41
+				private $local_token;
42
+
43
+				/**
44
+				 * @var Package
45
+				 */
46
+				private $package;
47
+
48
+				private $messages = [];
49
+
50
+				/**
51
+				 * Version constructor.
52
+				 * @param EntityManagerInterface $em
53
+				 * @param HttpClientInterface $client
54
+				 * @param ParameterBagInterface $parameter
55
+				 * @param PackagistApi $packagist
56
+				 */
57
+				public function __construct(EntityManagerInterface $em, HttpClientInterface $client, ParameterBagInterface $parameter, PackagistApi $packagist)
58
+				{
59
+								$this->em = $em;
60
+								$this->client = $client;
61
+								$this->parameter = $parameter;
62
+								$this->packagist = $packagist;
63
+								$this->local_token = $parameter->get("ribs_admin.packages_token");
64
+				}
65
+
66
+				/**
67
+				 * @return array
68
+				 */
69
+				public function getMessages(): array
70
+				{
71
+								return $this->messages;
72
+				}
73
+
74
+				/**
75
+				 * @param Package $package
76
+				 */
77
+				public function setPackageEntity(Package $package) {
78
+								$this->package = $package;
79
+				}
80
+
81
+				/**
82
+				 * @return mixed|null
83
+				 */
84
+				private function getToken()
85
+				{
86
+								$token = null;
87
+								$response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/");
88
+								$datas = $response->getStatusCode() == 200 ? $response->getContent() : null;
89
+
90
+								if ($datas) {
91
+												$token = json_decode($datas, true)["token"];
92
+								}
93
+
94
+								return $token;
95
+				}
96
+
97
+				/**
98
+				 * @return mixed|null
99
+				 * @throws ClientExceptionInterface
100
+				 * @throws RedirectionExceptionInterface
101
+				 * @throws ServerExceptionInterface
102
+				 * @throws TransportExceptionInterface
103
+				 */
104
+				private function getComposerLockJson()
105
+				{
106
+								if ($this->package && !$this->package->isIsLocal()) {
107
+												$response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl());
108
+												$composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
109
+								} else {
110
+												$composer_lock = file_get_contents('../composer.lock');
111
+								}
112
+
113
+								if ($composer_lock) {
114
+												return json_decode($composer_lock, true);
115
+								}
116
+
117
+								return null;
118
+				}
119
+
120
+				/**
121
+				 * @return mixed|null
122
+				 * @throws ClientExceptionInterface
123
+				 * @throws RedirectionExceptionInterface
124
+				 * @throws ServerExceptionInterface
125
+				 * @throws TransportExceptionInterface
126
+				 */
127
+				public function getPackage()
128
+				{
129
+								$composer_lock = $this->getComposerLockJson();
130
+								if ($composer_lock) {
131
+												$packages = $composer_lock["packages"];
132
+												$key = array_search($this->package->getPackageName(), array_column($packages, 'name'));
133
+
134
+												if ($key) {
135
+																return $packages[$key];
136
+												}
137
+								}
138
+
139
+								$this->messages["composer_lock"] = "Composer lock not found at " . $this->package->getProjectUrl();
140
+
141
+								return null;
142
+				}
143
+
144
+				/**
145
+				 * @return mixed|null
146
+				 */
147
+				public function getVersion()
148
+				{
149
+								return $this->getPackage($this->package->getPackageName()) ? $this->getPackage($this->package->getPackageName())["version"] : null;
150
+				}
151
+
152
+				/**
153
+				 * @return DateTime|null
154
+				 * @throws Exception
155
+				 */
156
+				public function getVersionDate(): ?DateTime
157
+				{
158
+								$string_date = $this->getPackage($this->package->getPackageName()) ? explode("T", $this->getPackage($this->package->getPackageName())["time"])[0] : null;
159
+								$version_date = null;
160
+
161
+								if ($string_date) {
162
+												$version_date = new DateTime($string_date);
163
+								}
164
+
165
+								return $version_date;
166
+				}
167
+
168
+				/**
169
+				 * @param $package_guid
170
+				 * @throws Exception
171
+				 */
172
+				public function save($package_guid)
173
+				{
174
+								$package = $this->em->getRepository(Package::class)->findOneBy(["guid" => $package_guid]);
175
+
176
+								if ($package) {
177
+												$this->setPackageEntity($package);
178
+
179
+												if (!$this->getToken() || $this->getToken() !== $this->local_token) {
180
+																$this->messages["token_error"] = "Token not matching on : " . $this->package->getProjectUrl();
181
+																return;
182
+												}
183
+
184
+												$package->setVersion($this->getVersion());
185
+												$package->setVersionDate($this->getVersionDate());
186
+												$package->setLastPackagistVersion($this->packagist->getLastPackagistVersion($package->getPackageName()));
187
+												$package->setLastCheck(new DateTime());
188
+
189
+												$this->em->persist($package);
190
+												$this->em->flush();
191
+								}
192
+				}
193 193
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     private function getToken()
85 85
     {
86 86
         $token = null;
87
-        $response = $this->client->request("GET", $this->package->getProjectUrl()."ribs-admin/packages/send-token/");
87
+        $response = $this->client->request("GET", $this->package->getProjectUrl() . "ribs-admin/packages/send-token/");
88 88
         $datas = $response->getStatusCode() == 200 ? $response->getContent() : null;
89 89
 
90 90
         if ($datas) {
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     private function getComposerLockJson()
105 105
     {
106 106
         if ($this->package && !$this->package->isIsLocal()) {
107
-            $response = $this->client->request("GET", $this->package->getProjectUrl().$this->package->getComposerLockUrl());
107
+            $response = $this->client->request("GET", $this->package->getProjectUrl() . $this->package->getComposerLockUrl());
108 108
             $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
109 109
         } else {
110 110
             $composer_lock = file_get_contents('../composer.lock');
Please login to merge, or discard this patch.
Service/PackagistApi.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -7,76 +7,76 @@
 block discarded – undo
7 7
 
8 8
 class PackagistApi
9 9
 {
10
-    /**
11
-     * @var HttpClientInterface
12
-     */
13
-    private $client;
10
+				/**
11
+				 * @var HttpClientInterface
12
+				 */
13
+				private $client;
14 14
 
15
-    /**
16
-     * @var string
17
-     */
18
-    private $package_name = null;
15
+				/**
16
+				 * @var string
17
+				 */
18
+				private $package_name = null;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private $package_info = [];
20
+				/**
21
+				 * @var array
22
+				 */
23
+				private $package_info = [];
24 24
 
25
-    /**
26
-     * PackagistApi constructor.
27
-     * @param HttpClientInterface $client
28
-     */
29
-    public function __construct(HttpClientInterface $client)
30
-    {
31
-        $this->client = $client;
32
-    }
25
+				/**
26
+				 * PackagistApi constructor.
27
+				 * @param HttpClientInterface $client
28
+				 */
29
+				public function __construct(HttpClientInterface $client)
30
+				{
31
+								$this->client = $client;
32
+				}
33 33
 
34
-    /**
35
-     * @return false|mixed
36
-     */
37
-    private function getPackageInformation()
38
-    {
39
-        if ($this->package_info) {
40
-            return $this->package_info;
41
-        }
34
+				/**
35
+				 * @return false|mixed
36
+				 */
37
+				private function getPackageInformation()
38
+				{
39
+								if ($this->package_info) {
40
+												return $this->package_info;
41
+								}
42 42
 
43
-        if (!$this->package_name || !strpos($this->package_name, "/")) {
44
-            return false;
45
-        }
43
+								if (!$this->package_name || !strpos($this->package_name, "/")) {
44
+												return false;
45
+								}
46 46
 
47
-        $packgist_url = "https://repo.packagist.org/p/".$this->package_name.".json";
48
-        $response = $this->client->request("GET", $packgist_url);
47
+								$packgist_url = "https://repo.packagist.org/p/".$this->package_name.".json";
48
+								$response = $this->client->request("GET", $packgist_url);
49 49
 
50
-        if ($response->getStatusCode() == 200) {
51
-            $content = json_decode($response->getContent(), true);
52
-            if (is_array($content) && $content["packages"] && $content["packages"][$this->package_name]) {
53
-                $this->package_info = $content["packages"][$this->package_name];
54
-                return $this->package_info;
55
-            }
56
-        }
50
+								if ($response->getStatusCode() == 200) {
51
+												$content = json_decode($response->getContent(), true);
52
+												if (is_array($content) && $content["packages"] && $content["packages"][$this->package_name]) {
53
+																$this->package_info = $content["packages"][$this->package_name];
54
+																return $this->package_info;
55
+												}
56
+								}
57 57
 
58
-        return false;
59
-    }
58
+								return false;
59
+				}
60 60
 
61
-    /**
62
-     * @param string $package_name
63
-     * @return false|int|string|null
64
-     */
65
-    public function getLastPackagistVersion(string $package_name)
66
-    {
67
-        $this->package_name = $package_name;
68
-        if ($package = $this->getPackageInformation()) {
69
-            return array_key_first($package);
70
-        }
61
+				/**
62
+				 * @param string $package_name
63
+				 * @return false|int|string|null
64
+				 */
65
+				public function getLastPackagistVersion(string $package_name)
66
+				{
67
+								$this->package_name = $package_name;
68
+								if ($package = $this->getPackageInformation()) {
69
+												return array_key_first($package);
70
+								}
71 71
 
72
-        return false;
73
-    }
72
+								return false;
73
+				}
74 74
 
75
-    public function getAllPackagistVersions(string $package_name)
76
-    {
77
-        $this->package_name = $package_name;
78
-        if ($package = $this->getPackageInformation()) {
79
-            return array_keys($package);
80
-        }
81
-    }
75
+				public function getAllPackagistVersions(string $package_name)
76
+				{
77
+								$this->package_name = $package_name;
78
+								if ($package = $this->getPackageInformation()) {
79
+												return array_keys($package);
80
+								}
81
+				}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
             return false;
45 45
         }
46 46
 
47
-        $packgist_url = "https://repo.packagist.org/p/".$this->package_name.".json";
47
+        $packgist_url = "https://repo.packagist.org/p/" . $this->package_name . ".json";
48 48
         $response = $this->client->request("GET", $packgist_url);
49 49
 
50 50
         if ($response->getStatusCode() == 200) {
Please login to merge, or discard this patch.