Skip to content

Commit 65a911f

Browse files
authored
Merge pull request #8 from dachcom-digital/coding-standard/refactor-master
[CS] Refactor
2 parents a5093dc + 17921c4 commit 65a911f

13 files changed

+166
-30
lines changed

src/Builder/SocialPostBuilder.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Builder;
415

516
use Carbon\Carbon;
617
use SocialData\Connector\LinkedIn\Client\LinkedInClient;
7-
use SocialDataBundle\Dto\BuildConfig;
818
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
919
use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
1020
use SocialDataBundle\Connector\SocialPostBuilderInterface;
21+
use SocialDataBundle\Dto\BuildConfig;
1122
use SocialDataBundle\Dto\FetchData;
1223
use SocialDataBundle\Dto\FilterData;
1324
use SocialDataBundle\Dto\TransformData;
@@ -192,7 +203,6 @@ protected function findThumbnail(mixed $media): ?string
192203
$thumbnail = null;
193204

194205
foreach ($media as $shareMedia) {
195-
196206
if (!isset($shareMedia['thumbnails']) || !is_array($shareMedia['thumbnails'])) {
197207
continue;
198208
}
@@ -210,6 +220,7 @@ protected function findThumbnail(mixed $media): ?string
210220

211221
if (isset($index[0], $validThumbs[$index[0]]['url'])) {
212222
$thumbnail = $validThumbs[$index[0]]['url'];
223+
213224
break;
214225
}
215226
}

src/Client/LinkedInClient.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Client;
415

516
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;

src/Client/LinkedInSDK.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Client;
415

516
/**
6-
* Adapted from https://github.com/ashwinks/PHP-LinkedIn-SDK
17+
* Adapted from https://github.com/ashwinks/PHP-LinkedIn-SDK.
718
*/
819
class LinkedInSDK
920
{
1021
protected const API_BASE = 'https://api.linkedin.com/v2';
1122
protected const OAUTH_BASE = 'https://www.linkedin.com/oauth/v2';
12-
1323
public const R_AD_CAMPAIGNS = 'r_ad_campaigns'; // View advertising campaigns you manage
1424
public const R_ADS = 'r_ads'; // Retrieve your advertising accounts
1525
public const R_ADS_LEADGEN_AUTOMATION = 'r_ads_leadgen_automation'; // Access your Lead Gen Forms and retrieve leads
@@ -26,7 +36,6 @@ class LinkedInSDK
2636
public const RW_ORGANIZATION = 'rw_organization'; // Manage your organization's page and post updates
2737
public const W_MEMBER_SOCIAL = 'w_member_social'; // Post, comment and like posts on your behalf
2838
public const W_ORGANIZATION_SOCIAL = 'w_organization_social'; // Post, comment and like posts on your organization's behalf
29-
3039
protected const HTTP_METHOD_GET = 'GET';
3140
protected const HTTP_METHOD_POST = 'POST';
3241
protected const HTTP_METHOD_PUT = 'PUT';
@@ -67,7 +76,7 @@ public function __construct(array $config)
6776
}
6877

6978
/**
70-
* Get the login url, pass scope to request specific permissions
79+
* Get the login url, pass scope to request specific permissions.
7180
*
7281
* @param array $scope - an array of requested permissions (can use scope constants defined in this class)
7382
* @param string|null $state - a unique identifier for this user, if none is passed, one is generated via uniqid
@@ -89,7 +98,7 @@ public function getLoginUrl(array $scope = [], ?string $state = null): string
8998
}
9099

91100
/**
92-
* Exchange the authorization code for access token
101+
* Exchange the authorization code for access token.
93102
*
94103
* @throws \RuntimeException
95104
* @throws \InvalidArgumentException
@@ -127,15 +136,15 @@ public function getAccessToken(?string $authorization_code = null): string|bool
127136
}
128137

129138
/**
130-
* This timestamp is "expires in". In other words, the token will expire in now() + expires_in
139+
* This timestamp is "expires in". In other words, the token will expire in now() + expires_in.
131140
*/
132141
public function getAccessTokenExpiration(): ?string
133142
{
134143
return $this->accessTokenExpires;
135144
}
136145

137146
/**
138-
* Set the access token manually
147+
* Set the access token manually.
139148
*
140149
* @throws \InvalidArgumentException
141150
*/
@@ -152,7 +161,7 @@ public function setAccessToken(string $token): self
152161
}
153162

154163
/**
155-
* Set the state manually. State is a unique identifier for the user
164+
* Set the state manually. State is a unique identifier for the user.
156165
*
157166
* @throws \InvalidArgumentException
158167
*/
@@ -169,31 +178,31 @@ public function setState(string $state): self
169178
}
170179

171180
/**
172-
* Get state
181+
* Get state.
173182
*/
174183
public function getState(): ?string
175184
{
176185
return $this->state;
177186
}
178187

179188
/**
180-
* GET an authenticated API endpoind w/ payload
189+
* GET an authenticated API endpoind w/ payload.
181190
*/
182191
public function get(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
183192
{
184193
return $this->fetch($endpoint, $payload, self::HTTP_METHOD_GET, $headers, $curlOptions);
185194
}
186195

187196
/**
188-
* GET an authenticated API endpoind w/ payload
197+
* GET an authenticated API endpoind w/ payload.
189198
*/
190199
public function getEncoded(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
191200
{
192201
return $this->fetch($endpoint, $payload, self::HTTP_METHOD_GET, $headers, $curlOptions, true);
193202
}
194203

195204
/**
196-
* POST to an authenticated API endpoint w/ payload
205+
* POST to an authenticated API endpoint w/ payload.
197206
*/
198207
public function post(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
199208
{
@@ -203,7 +212,7 @@ public function post(string $endpoint, array $payload = [], array $headers = [],
203212
}
204213

205214
/**
206-
* PUT to an authenticated API endpoint w/ payload
215+
* PUT to an authenticated API endpoint w/ payload.
207216
*/
208217
public function put(string $endpoint, array $payload = [], array $headers = [], array $curlOptions = []): array
209218
{
@@ -230,15 +239,15 @@ public function fetchOAuth(string $endpoint, array $payload = [], string $method
230239
}
231240

232241
/**
233-
* Get debug info from the CURL request
242+
* Get debug info from the CURL request.
234243
*/
235244
public function getDebugInfo(): ?array
236245
{
237246
return $this->debugInfo;
238247
}
239248

240249
/**
241-
* Make a CURL request
250+
* Make a CURL request.
242251
*
243252
* @throws \JsonException
244253
*/
@@ -250,7 +259,6 @@ protected function _makeRequest(
250259
array $curlOptions = [],
251260
bool $useEncodedQuery = false
252261
): array {
253-
254262
$ch = $this->_getCurlHandle();
255263

256264
$options = [
@@ -264,14 +272,12 @@ protected function _makeRequest(
264272

265273
if (!empty($payload)) {
266274
if (in_array($options[CURLOPT_CUSTOMREQUEST], [self::HTTP_METHOD_POST, self::HTTP_METHOD_PUT], true)) {
267-
268275
$options[CURLOPT_POST] = true;
269276
$options[CURLOPT_POSTFIELDS] = http_build_query($payload);
270277

271278
$headers[] = 'Content-Length: ' . strlen($options[CURLOPT_POSTFIELDS]);
272279

273280
$options[CURLOPT_HTTPHEADER] = $headers;
274-
275281
} else {
276282
$query = http_build_query($payload);
277283
$options[CURLOPT_URL] = sprintf('%s&%s', $options[CURLOPT_URL], ($useEncodedQuery ? urldecode($query) : $query));
@@ -314,5 +320,4 @@ public function __destruct()
314320
curl_close($this->curlHandle);
315321
}
316322
}
317-
318-
}
323+
}

src/Controller/Admin/LinkedInController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Controller\Admin;
415

516
use Carbon\Carbon;
617
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
7-
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
818
use SocialData\Connector\LinkedIn\Client\LinkedInClient;
19+
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
920
use SocialDataBundle\Connector\ConnectorDefinitionInterface;
1021
use SocialDataBundle\Controller\Admin\Traits\ConnectResponseTrait;
1122
use SocialDataBundle\Service\ConnectorServiceInterface;
@@ -95,7 +106,6 @@ public function debugTokenAction(Request $request): JsonResponse
95106
}
96107

97108
try {
98-
99109
$payload = [
100110
'client_id' => $connectorEngineConfig->getClientId(),
101111
'client_secret' => $connectorEngineConfig->getClientSecret(),

src/Definition/ConnectorDefinition.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Definition;
415

516
use SocialData\Connector\LinkedIn\Client\LinkedInSDK;
617
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;
718
use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
8-
use SocialDataBundle\Connector\ConnectorEngineConfigurationInterface;
919
use SocialDataBundle\Connector\ConnectorDefinitionInterface;
20+
use SocialDataBundle\Connector\ConnectorEngineConfigurationInterface;
1021
use SocialDataBundle\Connector\SocialPostBuilderInterface;
1122
use SocialDataBundle\Model\ConnectorEngineInterface;
1223
use Symfony\Component\OptionsResolver\OptionsResolver;

src/DependencyInjection/Configuration.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\DependencyInjection;
415

516
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

src/DependencyInjection/SocialDataLinkedInConnectorExtension.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\DependencyInjection;
415

16+
use Symfony\Component\Config\FileLocator;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
518
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
619
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
7-
use Symfony\Component\DependencyInjection\ContainerBuilder;
8-
use Symfony\Component\Config\FileLocator;
920

1021
class SocialDataLinkedInConnectorExtension extends Extension
1122
{

src/EventListener/Admin/AssetListener.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\EventListener\Admin;
415

516
use Pimcore\Event\BundleManager\PathsEvent;

src/Form/Admin/Type/LinkedInEngineType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Form\Admin\Type;
415

516
use SocialData\Connector\LinkedIn\Model\EngineConfiguration;

src/Form/Admin/Type/LinkedInFeedType.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This source file is available under two different licenses:
5+
* - GNU General Public License version 3 (GPLv3)
6+
* - DACHCOM Commercial License (DCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
11+
* @license GPLv3 and DCL
12+
*/
13+
314
namespace SocialData\Connector\LinkedIn\Form\Admin\Type;
415

516
use SocialData\Connector\LinkedIn\Model\FeedConfiguration;
@@ -21,7 +32,7 @@ public function configureOptions(OptionsResolver $resolver): void
2132
{
2233
$resolver->setDefaults([
2334
'csrf_protection' => false,
24-
'data_class' => FeedConfiguration::class
35+
'data_class' => FeedConfiguration::class
2536
]);
2637
}
2738
}

0 commit comments

Comments
 (0)