Passed
Push — master ( bf85fc...c1490b )
by Anthony
09:13
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
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.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -11,92 +11,92 @@
 block discarded – undo
11 11
 
12 12
 class PackagistApi
13 13
 {
14
-    /**
15
-     * @var HttpClientInterface
16
-     */
17
-    private $client;
14
+				/**
15
+				 * @var HttpClientInterface
16
+				 */
17
+				private $client;
18 18
 
19
-    /**
20
-     * @var string
21
-     */
22
-    private $package_name = null;
19
+				/**
20
+				 * @var string
21
+				 */
22
+				private $package_name = null;
23 23
 
24
-    /**
25
-     * @var array
26
-     */
27
-    private $package_info = [];
24
+				/**
25
+				 * @var array
26
+				 */
27
+				private $package_info = [];
28 28
 
29
-    /**
30
-     * PackagistApi constructor.
31
-     * @param HttpClientInterface $client
32
-     */
33
-    public function __construct(HttpClientInterface $client)
34
-    {
35
-        $this->client = $client;
36
-    }
29
+				/**
30
+				 * PackagistApi constructor.
31
+				 * @param HttpClientInterface $client
32
+				 */
33
+				public function __construct(HttpClientInterface $client)
34
+				{
35
+								$this->client = $client;
36
+				}
37 37
 
38
-    /**
39
-     * @return false|mixed
40
-     * @throws ClientExceptionInterface
41
-     * @throws RedirectionExceptionInterface
42
-     * @throws ServerExceptionInterface
43
-     * @throws TransportExceptionInterface
44
-     */
45
-    private function getPackageInformation()
46
-    {
47
-        if ($this->package_info) {
48
-            return $this->package_info;
49
-        }
38
+				/**
39
+				 * @return false|mixed
40
+				 * @throws ClientExceptionInterface
41
+				 * @throws RedirectionExceptionInterface
42
+				 * @throws ServerExceptionInterface
43
+				 * @throws TransportExceptionInterface
44
+				 */
45
+				private function getPackageInformation()
46
+				{
47
+								if ($this->package_info) {
48
+												return $this->package_info;
49
+								}
50 50
 
51
-        if (!$this->package_name || !strpos($this->package_name, "/")) {
52
-            return false;
53
-        }
51
+								if (!$this->package_name || !strpos($this->package_name, "/")) {
52
+												return false;
53
+								}
54 54
 
55
-        $packgist_url = "https://repo.packagist.org/p/".$this->package_name.".json";
56
-        $response = $this->client->request("GET", $packgist_url);
55
+								$packgist_url = "https://repo.packagist.org/p/".$this->package_name.".json";
56
+								$response = $this->client->request("GET", $packgist_url);
57 57
 
58
-        if ($response->getStatusCode() == 200) {
59
-            $content = json_decode($response->getContent(), true);
60
-            if (is_array($content) && $content["packages"] && $content["packages"][$this->package_name]) {
61
-                $this->package_info = $content["packages"][$this->package_name];
62
-                return $this->package_info;
63
-            }
64
-        }
58
+								if ($response->getStatusCode() == 200) {
59
+												$content = json_decode($response->getContent(), true);
60
+												if (is_array($content) && $content["packages"] && $content["packages"][$this->package_name]) {
61
+																$this->package_info = $content["packages"][$this->package_name];
62
+																return $this->package_info;
63
+												}
64
+								}
65 65
 
66
-        return false;
67
-    }
66
+								return false;
67
+				}
68 68
 
69
-    /**
70
-     * @param string $package_name
71
-     * @return false|int|string|null
72
-     * @throws ClientExceptionInterface
73
-     * @throws RedirectionExceptionInterface
74
-     * @throws ServerExceptionInterface
75
-     * @throws TransportExceptionInterface
76
-     */
77
-    public function getLastPackagistVersion(string $package_name)
78
-    {
79
-        $this->package_name = $package_name;
80
-        if ($package = $this->getPackageInformation()) {
81
-            return array_key_first($package);
82
-        }
69
+				/**
70
+				 * @param string $package_name
71
+				 * @return false|int|string|null
72
+				 * @throws ClientExceptionInterface
73
+				 * @throws RedirectionExceptionInterface
74
+				 * @throws ServerExceptionInterface
75
+				 * @throws TransportExceptionInterface
76
+				 */
77
+				public function getLastPackagistVersion(string $package_name)
78
+				{
79
+								$this->package_name = $package_name;
80
+								if ($package = $this->getPackageInformation()) {
81
+												return array_key_first($package);
82
+								}
83 83
 
84
-        return false;
85
-    }
84
+								return false;
85
+				}
86 86
 
87
-    /**
88
-     * @param string $package_name
89
-     * @return array
90
-     * @throws ClientExceptionInterface
91
-     * @throws RedirectionExceptionInterface
92
-     * @throws ServerExceptionInterface
93
-     * @throws TransportExceptionInterface
94
-     */
95
-    public function getAllPackagistVersions(string $package_name)
96
-    {
97
-        $this->package_name = $package_name;
98
-        if ($package = $this->getPackageInformation()) {
99
-            return array_keys($package);
100
-        }
101
-    }
87
+				/**
88
+				 * @param string $package_name
89
+				 * @return array
90
+				 * @throws ClientExceptionInterface
91
+				 * @throws RedirectionExceptionInterface
92
+				 * @throws ServerExceptionInterface
93
+				 * @throws TransportExceptionInterface
94
+				 */
95
+				public function getAllPackagistVersions(string $package_name)
96
+				{
97
+								$this->package_name = $package_name;
98
+								if ($package = $this->getPackageInformation()) {
99
+												return array_keys($package);
100
+								}
101
+				}
102 102
 }
Please login to merge, or discard this patch.