Passed
Push — master ( e1851e...bd79b7 )
by Anthony
02:56
created
Service/Version.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -12,159 +12,159 @@
 block discarded – undo
12 12
 
13 13
 class Version
14 14
 {
15
-    /**
16
-     * @var EntityManagerInterface
17
-     */
18
-    private $em;
19
-
20
-    /**
21
-     * @var HttpClientInterface
22
-     */
23
-    private $client;
24
-
25
-    /**
26
-     * @var \PiouPiou\RibsAdminBundle\Entity\Version
27
-     */
28
-    private $version_entity;
29
-
30
-    /**
31
-     * Version constructor.
32
-     * @param EntityManagerInterface $em
33
-     * @param HttpClientInterface $client
34
-     */
35
-    public function __construct(EntityManagerInterface $em, HttpClientInterface $client)
36
-    {
37
-        $this->em = $em;
38
-        $this->client = $client;
39
-    }
40
-
41
-    /**
42
-     * @param \PiouPiou\RibsAdminBundle\Entity\Version $version
43
-     */
44
-    public function setVersionEntity(\PiouPiou\RibsAdminBundle\Entity\Version $version) {
45
-        $this->version_entity = $version;
46
-    }
47
-
48
-    /**
49
-     * @return mixed|null
50
-     * @throws ClientExceptionInterface
51
-     * @throws RedirectionExceptionInterface
52
-     * @throws ServerExceptionInterface
53
-     * @throws TransportExceptionInterface
54
-     */
55
-    private function getComposerLockJson()
56
-    {
57
-        if ($this->version_entity && !$this->version_entity->isIsLocal()) {
58
-            $response = $this->client->request("GET", $this->version_entity->getProjectUrl().$this->version_entity->getComposerLockUrl());
59
-            $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
60
-        } else {
61
-            $composer_lock = file_get_contents('../composer.lock');
62
-        }
63
-
64
-        if ($composer_lock) {
65
-            return json_decode($composer_lock, true);
66
-        }
67
-
68
-        return null;
69
-    }
70
-
71
-    /**
72
-     * @param $package_name
73
-     * @return mixed|null
74
-     * @throws ClientExceptionInterface
75
-     * @throws RedirectionExceptionInterface
76
-     * @throws ServerExceptionInterface
77
-     * @throws TransportExceptionInterface
78
-     */
79
-    private function getPackage($package_name)
80
-    {
81
-        $composer_lock = $this->getComposerLockJson();
82
-        if ($composer_lock) {
83
-            $packages = $composer_lock["packages"];
84
-            $key = array_search($package_name, array_column($packages, 'name'));
85
-
86
-            if ($key) {
87
-                return $packages[$key];
88
-            }
89
-        }
90
-
91
-        return null;
92
-    }
93
-
94
-    /**
95
-     * @param $package_name
96
-     * @return mixed|null
97
-     */
98
-    public function getVersion($package_name)
99
-    {
100
-        return $this->getPackage($package_name) ? $this->getPackage($package_name)["version"] : null;
101
-    }
102
-
103
-    /**
104
-     * @param $package_name
105
-     * @return mixed|null
106
-     * @throws Exception
107
-     */
108
-    public function getVersionDate($package_name)
109
-    {
110
-        $string_date = $this->getPackage($package_name) ? explode("T", $this->getPackage($package_name)["time"])[0] : null;
111
-        $version_date = null;
112
-
113
-        if ($string_date) {
114
-            $version_date = new \DateTime($string_date);
115
-        }
116
-
117
-        return $version_date;
118
-    }
119
-
120
-    /**
121
-     * @param $package_name
122
-     * @return false|int|string|null
123
-     * @throws ClientExceptionInterface
124
-     * @throws RedirectionExceptionInterface
125
-     * @throws ServerExceptionInterface
126
-     * @throws TransportExceptionInterface
127
-     */
128
-    public function getLastPackagistVersion($package_name)
129
-    {
130
-        if (!strpos($package_name, "/")) {
131
-            return false;
132
-        }
133
-
134
-        $packgist_url = "https://repo.packagist.org/p/".$package_name.".json";
135
-
136
-        $response = $this->client->request("GET", $packgist_url);
137
-
138
-        if ($response->getStatusCode() == 200) {
139
-            $content = json_decode($response->getContent(), true);
140
-            if (is_array($content) && $content["packages"] && $content["packages"][$package_name]) {
141
-                return array_key_first($content["packages"][$package_name]);
142
-            }
143
-        }
144
-    }
145
-
146
-    /**
147
-     * @param $package_name
148
-     * @throws Exception
149
-     */
150
-    public function save($package_name)
151
-    {
152
-        $version = $this->em->getRepository(\PiouPiou\RibsAdminBundle\Entity\Version::class)->findOneBy(["package_name" => $package_name]);
153
-
154
-        if (!$version) {
155
-            $version = new \PiouPiou\RibsAdminBundle\Entity\Version();
156
-            $version->setProjectName($package_name);
157
-            $version->setPackageName($package_name);
158
-            $version->setProjectUrl($package_name);
159
-            $version->setCheckVersionUrl($package_name);
160
-        }
161
-
162
-        $version->setVersion($this->getVersion($package_name));
163
-        $version->setVersionDate($this->getVersionDate($package_name));
164
-        $version->setLastPackagistVersion($this->getLastPackagistVersion($package_name));
165
-        $version->setLastCheck(new \DateTime());
166
-
167
-        $this->em->persist($version);
168
-        $this->em->flush();
169
-    }
15
+				/**
16
+				 * @var EntityManagerInterface
17
+				 */
18
+				private $em;
19
+
20
+				/**
21
+				 * @var HttpClientInterface
22
+				 */
23
+				private $client;
24
+
25
+				/**
26
+				 * @var \PiouPiou\RibsAdminBundle\Entity\Version
27
+				 */
28
+				private $version_entity;
29
+
30
+				/**
31
+				 * Version constructor.
32
+				 * @param EntityManagerInterface $em
33
+				 * @param HttpClientInterface $client
34
+				 */
35
+				public function __construct(EntityManagerInterface $em, HttpClientInterface $client)
36
+				{
37
+								$this->em = $em;
38
+								$this->client = $client;
39
+				}
40
+
41
+				/**
42
+				 * @param \PiouPiou\RibsAdminBundle\Entity\Version $version
43
+				 */
44
+				public function setVersionEntity(\PiouPiou\RibsAdminBundle\Entity\Version $version) {
45
+								$this->version_entity = $version;
46
+				}
47
+
48
+				/**
49
+				 * @return mixed|null
50
+				 * @throws ClientExceptionInterface
51
+				 * @throws RedirectionExceptionInterface
52
+				 * @throws ServerExceptionInterface
53
+				 * @throws TransportExceptionInterface
54
+				 */
55
+				private function getComposerLockJson()
56
+				{
57
+								if ($this->version_entity && !$this->version_entity->isIsLocal()) {
58
+												$response = $this->client->request("GET", $this->version_entity->getProjectUrl().$this->version_entity->getComposerLockUrl());
59
+												$composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
60
+								} else {
61
+												$composer_lock = file_get_contents('../composer.lock');
62
+								}
63
+
64
+								if ($composer_lock) {
65
+												return json_decode($composer_lock, true);
66
+								}
67
+
68
+								return null;
69
+				}
70
+
71
+				/**
72
+				 * @param $package_name
73
+				 * @return mixed|null
74
+				 * @throws ClientExceptionInterface
75
+				 * @throws RedirectionExceptionInterface
76
+				 * @throws ServerExceptionInterface
77
+				 * @throws TransportExceptionInterface
78
+				 */
79
+				private function getPackage($package_name)
80
+				{
81
+								$composer_lock = $this->getComposerLockJson();
82
+								if ($composer_lock) {
83
+												$packages = $composer_lock["packages"];
84
+												$key = array_search($package_name, array_column($packages, 'name'));
85
+
86
+												if ($key) {
87
+																return $packages[$key];
88
+												}
89
+								}
90
+
91
+								return null;
92
+				}
93
+
94
+				/**
95
+				 * @param $package_name
96
+				 * @return mixed|null
97
+				 */
98
+				public function getVersion($package_name)
99
+				{
100
+								return $this->getPackage($package_name) ? $this->getPackage($package_name)["version"] : null;
101
+				}
102
+
103
+				/**
104
+				 * @param $package_name
105
+				 * @return mixed|null
106
+				 * @throws Exception
107
+				 */
108
+				public function getVersionDate($package_name)
109
+				{
110
+								$string_date = $this->getPackage($package_name) ? explode("T", $this->getPackage($package_name)["time"])[0] : null;
111
+								$version_date = null;
112
+
113
+								if ($string_date) {
114
+												$version_date = new \DateTime($string_date);
115
+								}
116
+
117
+								return $version_date;
118
+				}
119
+
120
+				/**
121
+				 * @param $package_name
122
+				 * @return false|int|string|null
123
+				 * @throws ClientExceptionInterface
124
+				 * @throws RedirectionExceptionInterface
125
+				 * @throws ServerExceptionInterface
126
+				 * @throws TransportExceptionInterface
127
+				 */
128
+				public function getLastPackagistVersion($package_name)
129
+				{
130
+								if (!strpos($package_name, "/")) {
131
+												return false;
132
+								}
133
+
134
+								$packgist_url = "https://repo.packagist.org/p/".$package_name.".json";
135
+
136
+								$response = $this->client->request("GET", $packgist_url);
137
+
138
+								if ($response->getStatusCode() == 200) {
139
+												$content = json_decode($response->getContent(), true);
140
+												if (is_array($content) && $content["packages"] && $content["packages"][$package_name]) {
141
+																return array_key_first($content["packages"][$package_name]);
142
+												}
143
+								}
144
+				}
145
+
146
+				/**
147
+				 * @param $package_name
148
+				 * @throws Exception
149
+				 */
150
+				public function save($package_name)
151
+				{
152
+								$version = $this->em->getRepository(\PiouPiou\RibsAdminBundle\Entity\Version::class)->findOneBy(["package_name" => $package_name]);
153
+
154
+								if (!$version) {
155
+												$version = new \PiouPiou\RibsAdminBundle\Entity\Version();
156
+												$version->setProjectName($package_name);
157
+												$version->setPackageName($package_name);
158
+												$version->setProjectUrl($package_name);
159
+												$version->setCheckVersionUrl($package_name);
160
+								}
161
+
162
+								$version->setVersion($this->getVersion($package_name));
163
+								$version->setVersionDate($this->getVersionDate($package_name));
164
+								$version->setLastPackagistVersion($this->getLastPackagistVersion($package_name));
165
+								$version->setLastCheck(new \DateTime());
166
+
167
+								$this->em->persist($version);
168
+								$this->em->flush();
169
+				}
170 170
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     private function getComposerLockJson()
56 56
     {
57 57
         if ($this->version_entity && !$this->version_entity->isIsLocal()) {
58
-            $response = $this->client->request("GET", $this->version_entity->getProjectUrl().$this->version_entity->getComposerLockUrl());
58
+            $response = $this->client->request("GET", $this->version_entity->getProjectUrl() . $this->version_entity->getComposerLockUrl());
59 59
             $composer_lock = $response->getStatusCode() == 200 ? $response->getContent() : null;
60 60
         } else {
61 61
             $composer_lock = file_get_contents('../composer.lock');
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             return false;
132 132
         }
133 133
 
134
-        $packgist_url = "https://repo.packagist.org/p/".$package_name.".json";
134
+        $packgist_url = "https://repo.packagist.org/p/" . $package_name . ".json";
135 135
 
136 136
         $response = $this->client->request("GET", $packgist_url);
137 137
 
Please login to merge, or discard this patch.