Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 55dbd72

Browse files
authored
Merge pull request #15 from itk-dev/feature/coding-standards
Coding standards
2 parents 0a6c5eb + ff9128a commit 55dbd72

File tree

10 files changed

+231
-96
lines changed

10 files changed

+231
-96
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor

.php-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
}
1111
],
1212
"repositories": [
13+
{
14+
"//": "https://git.drupalcode.org/issue/webform_embed-3149360/-/tree/3149360-automated-drupal-9",
15+
"type": "package",
16+
"package": {
17+
"name": "drupal/webform_embed",
18+
"//": "@see https://github.com/OS2Forms/os2forms/blob/master/composer.json#L27",
19+
"version": "1.x-dev",
20+
"type": "drupal-module",
21+
"source": {
22+
"url": "https://git.drupalcode.org/issue/webform_embed-3149360.git",
23+
"type": "git",
24+
"reference": "3149360-automated-drupal-9"
25+
}
26+
}
27+
},
1328
{
1429
"type": "composer",
1530
"url": "https://packages.drupal.org/8"
@@ -49,5 +64,11 @@
4964
"coding-standards-apply": [
5065
"@coding-standards-apply/phpcs"
5166
]
67+
},
68+
"config": {
69+
"allow-plugins": {
70+
"dealerdirect/phpcodesniffer-composer-installer": true,
71+
"vaimo/composer-patches": true
72+
}
5273
}
5374
}

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<description>The coding standard.</description>
44

55
<file>.</file>
6+
<exclude-pattern>generated-sources/</exclude-pattern>
67
<exclude-pattern>vendor/</exclude-pattern>
8+
<exclude-pattern>src/Client/</exclude-pattern>
79

810
<!-- Show progress of the run -->
911
<arg value="p"/>

src/Commands/CreatePdf.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CreatePdf extends DrushCommands {
1616
/**
1717
* The os2forms_digital_post template manager.
1818
*
19-
* @var TemplateManager
19+
* @var \Drupal\os2forms_digital_post\Manager\TemplateManager
2020
*/
2121
protected TemplateManager $templateManager;
2222

@@ -27,6 +27,9 @@ class CreatePdf extends DrushCommands {
2727
*/
2828
protected $entityTypeManager;
2929

30+
/**
31+
* Constructor.
32+
*/
3033
public function __construct(TemplateManager $templateManager, EntityTypeManagerInterface $entity_type_manager) {
3134
parent::__construct();
3235
$this->templateManager = $templateManager;
@@ -49,7 +52,11 @@ public function __construct(TemplateManager $templateManager, EntityTypeManagerI
4952
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
5053
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
5154
*/
52-
public function create($template, $options = ['submission_id' => 0, 'file_location' => '', 'file_name' => 'test.pdf']) {
55+
public function create($template, array $options = [
56+
'submission_id' => 0,
57+
'file_location' => '',
58+
'file_name' => 'test.pdf',
59+
]) {
5360
$elements[] = [];
5461
$webformLabel = '';
5562
$webform_submission = $this->entityTypeManager->getStorage('webform_submission')->load($options['submission_id']);
@@ -91,4 +98,5 @@ public function create($template, $options = ['submission_id' => 0, 'file_locati
9198
file_put_contents($filePath, $pdf);
9299
$this->output()->writeln(sprintf('Pdf written to %s', $filePath));
93100
}
101+
94102
}

src/Consumer/PrintServiceConsumer.php

Lines changed: 114 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\os2forms_digital_post\Consumer;
44

5+
use Drupal\Core\Config\ImmutableConfig;
56
use Drupal\Core\Config\ConfigFactoryInterface;
67
use Drupal\Core\Lock\LockBackendInterface;
78
use Drupal\Core\State\State;
@@ -17,27 +18,64 @@
1718
use Drupal\os2forms_digital_post\Client\StructType\KontaktOplysningType;
1819
use Drupal\os2forms_digital_post\Client\StructType\PrintAfsendBrevRequestType;
1920
use Drupal\os2forms_digital_post\Client\StructType\SlutbrugerIdentitetType;
20-
use Exception;
2121
use ItkDev\Serviceplatformen\Certificate\AzureKeyVaultCertificateLocator;
2222
use ItkDev\Serviceplatformen\Certificate\CertificateLocatorInterface;
23-
use SoapFault;
2423
use WsdlToPhp\PackageBase\AbstractSoapClientBase;
2524
use GuzzleHttp\Client;
2625
use Http\Factory\Guzzle\RequestFactory;
2726
use ItkDev\AzureKeyVault\Authorisation\VaultToken;
2827
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
2928
use ItkDev\AzureKeyVault\KeyVault\VaultSecret;
3029

30+
/**
31+
* Print service consumer.
32+
*/
3133
class PrintServiceConsumer {
32-
33-
private $config;
34-
private $guzzleClient;
35-
private $lock;
36-
private $state;
34+
/**
35+
* The config.
36+
*
37+
* @var \Drupal\Core\Config\ImmutableConfig
38+
*/
39+
private ImmutableConfig $config;
40+
41+
/**
42+
* The client.
43+
*
44+
* @var \GuzzleHttp\Client
45+
*/
46+
private Client $guzzleClient;
47+
48+
/**
49+
* The lock.
50+
*
51+
* @var \Drupal\Core\Lock\LockBackendInterface
52+
*/
53+
private LockBackendInterface $lock;
54+
55+
/**
56+
* The state.
57+
*
58+
* @var \Drupal\Core\State\State
59+
*/
60+
private State $state;
61+
62+
/**
63+
* The UUID generator.
64+
*
65+
* @var UuidInterface
66+
*/
3767
private $uuid;
3868

69+
/**
70+
* The lock name.
71+
*
72+
* @var string
73+
*/
3974
private $lockName = 'os2forms_digital_post_print_service';
4075

76+
/**
77+
* Constructor.
78+
*/
4179
public function __construct(ConfigFactoryInterface $configFactory, Client $guzzleClient, LockBackendInterface $lock, State $state) {
4280

4381
$this->config = $configFactory->get('os2forms_digital_post');
@@ -47,25 +85,28 @@ public function __construct(ConfigFactoryInterface $configFactory, Client $guzzl
4785
$this->uuid = \Drupal::service('uuid');
4886
}
4987

88+
/**
89+
* Afsend brev person.
90+
*/
5091
public function afsendBrevPerson(
51-
string $kanalValg = null,
52-
string $prioritet = null,
53-
string $cprNummerIdentifikator = null,
54-
string $personName = null,
55-
string $coNavn = null,
56-
string $streetName = null,
57-
string $streetBuildingIdentifier = null,
58-
string $floorIdentifier = null,
59-
string $suiteIdentifier = null,
60-
string $mailDeliverySublocationIdentifier = null,
61-
string $postCodeIdentifier = null,
62-
string $districtSubdivisionIdentifier = null,
63-
string $postOfficeBoxIdentifier = null,
64-
string $countryIdentificationCode = null,
65-
string $filFormatNavn = null,
66-
string $meddelelseIndholdData = null,
67-
string $titelTekst = null,
68-
string $brevDato = null
92+
string $kanalValg = NULL,
93+
string $prioritet = NULL,
94+
string $cprNummerIdentifikator = NULL,
95+
string $personName = NULL,
96+
string $coNavn = NULL,
97+
string $streetName = NULL,
98+
string $streetBuildingIdentifier = NULL,
99+
string $floorIdentifier = NULL,
100+
string $suiteIdentifier = NULL,
101+
string $mailDeliverySublocationIdentifier = NULL,
102+
string $postCodeIdentifier = NULL,
103+
string $districtSubdivisionIdentifier = NULL,
104+
string $postOfficeBoxIdentifier = NULL,
105+
string $countryIdentificationCode = NULL,
106+
string $filFormatNavn = NULL,
107+
string $meddelelseIndholdData = NULL,
108+
string $titelTekst = NULL,
109+
string $brevDato = NULL
69110
) {
70111

71112
if (!$this->acquireLock()) {
@@ -94,12 +135,12 @@ public function afsendBrevPerson(
94135
$postCodeIdentifier,
95136
$districtSubdivisionIdentifier,
96137
$postOfficeBoxIdentifier,
97-
null,
98-
null,
99-
null,
100-
null,
101-
null,
102-
null,
138+
NULL,
139+
NULL,
140+
NULL,
141+
NULL,
142+
NULL,
143+
NULL,
103144
$countryIdentificationCodeType
104145
);
105146

@@ -114,10 +155,10 @@ public function afsendBrevPerson(
114155
$forsendelsesModtager,
115156
$filFormatNavn,
116157
$meddelelseIndholdData,
117-
null,
158+
NULL,
118159
$dokumentParametre,
119-
null,
120-
null,
160+
NULL,
161+
NULL,
121162
$digitalPostParametre
122163
);
123164

@@ -140,21 +181,24 @@ public function afsendBrevPerson(
140181
AbstractSoapClientBase::WSDL_LOCATION => $this->config->get('service_endpoint'),
141182
]);
142183

143-
144184
$response = $client->afsendBrev($request);
145185

146186
$this->releaseLock();
147187

148-
if (false === $response) {
188+
if (FALSE === $response) {
149189
$lastError = $client->getLastError();
150-
/* @var $soapError SoapFault */
190+
/** @var SoapFault $soapError */
151191
$soapError = $lastError['Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev'];
152-
throw new Exception($soapError->getMessage(), $soapError->getCode()); // Should maybe log this instead!
192+
// Should maybe log this instead!
193+
throw new \Exception($soapError->getMessage(), $soapError->getCode());
153194
}
154195

155196
return $response->getResultat();
156197
}
157198

199+
/**
200+
* Get absolute path to certificate.
201+
*/
158202
private function getAzureKeyVaultCertificateLocator(
159203
string $tenantId,
160204
string $applicationId,
@@ -188,13 +232,16 @@ private function getAzureKeyVaultCertificateLocator(
188232
);
189233
}
190234

235+
/**
236+
* Afsend digital post person.
237+
*/
191238
public function afsendDigitalPostPerson(
192-
string $kanalValg = null,
193-
string $prioritet = null,
194-
string $cprNummerIdentifikator = null,
195-
string $filFormatNavn = null,
196-
string $meddelelseIndholdData = null,
197-
string $titelTekst = null
239+
string $kanalValg = NULL,
240+
string $prioritet = NULL,
241+
string $cprNummerIdentifikator = NULL,
242+
string $filFormatNavn = NULL,
243+
string $meddelelseIndholdData = NULL,
244+
string $titelTekst = NULL
198245
): bool {
199246

200247
if (!$this->acquireLock()) {
@@ -213,18 +260,18 @@ public function afsendDigitalPostPerson(
213260
$forsendelsesModtager = new ForsendelseModtagerType($slutBrugerIdentitetType);
214261

215262
$dokumentParametre = new DokumentParametreType($titelTekst);
216-
$digitalPostParametre = new DigitalPostParametreType(null, $this->config->get('digital_post_materiale_id'));
263+
$digitalPostParametre = new DigitalPostParametreType(NULL, $this->config->get('digital_post_materiale_id'));
217264

218265
$forsendelse = new ForsendelseIType(
219266
$this->generateAfsendelseIdentifikator(),
220-
null,
267+
NULL,
221268
$forsendelsesModtager,
222269
$filFormatNavn,
223270
$meddelelseIndholdData,
224-
null,
271+
NULL,
225272
$dokumentParametre,
226-
null,
227-
null,
273+
NULL,
274+
NULL,
228275
$digitalPostParametre
229276
);
230277

@@ -247,21 +294,24 @@ public function afsendDigitalPostPerson(
247294
AbstractSoapClientBase::WSDL_LOCATION => $this->config->get('service_endpoint'),
248295
]);
249296

250-
251297
$response = $client->afsendBrev($request);
252298

253299
$this->releaseLock();
254300

255-
if (false === $response) {
301+
if (FALSE === $response) {
256302
$lastError = $client->getLastError();
257-
/* @var $soapError SoapFault */
303+
/** @var SoapFault $soapError */
258304
$soapError = $lastError['Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev'];
259-
throw new \Exception($soapError->getMessage(), $soapError->getCode()); // Should maybe log this instead!
305+
// Should maybe log this instead!
306+
throw new \Exception($soapError->getMessage(), $soapError->getCode());
260307
}
261308

262309
return $response->getResultat();
263310
}
264311

312+
/**
313+
* Generate afsendelse identifikator.
314+
*/
265315
protected function generateAfsendelseIdentifikator(): string {
266316

267317
$stateKey = 'os2forms_digital_post_last_letter_counter';
@@ -276,19 +326,28 @@ protected function generateAfsendelseIdentifikator(): string {
276326

277327
return $this->config->get('digital_post_system_id')
278328
. $this->config->get('digital_post_afsender_system')
279-
. $nextLetterNumber
280-
;
329+
. $nextLetterNumber;
281330
}
282331

332+
/**
333+
* Acquire lock.
334+
*/
283335
protected function acquireLock(): bool {
284336
return $this->lock->acquire($this->lockName);
285337
}
286338

339+
/**
340+
* Release lock.
341+
*/
287342
protected function releaseLock() {
288343
$this->lock->release($this->lockName);
289344
}
290345

346+
/**
347+
* Wait lock.
348+
*/
291349
protected function waitLock(): bool {
292350
return $this->lock->wait($this->lockName);
293351
}
352+
294353
}

src/Exception/CprElementNotFoundInSubmissionException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Drupal\os2forms_digital_post\Exception;
44

5+
/**
6+
* Cpr Element Not Found In Submission Exception.
7+
*/
58
class CprElementNotFoundInSubmissionException extends \Exception {
69

710
}

0 commit comments

Comments
 (0)