Passed
Pull Request — master (#270)
by Guilherme
08:58
created

ClientMetadata::setRegistrationAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Entity;
12
13
use LoginCidadao\CoreBundle\Model\PersonInterface;
14
use LoginCidadao\OAuthBundle\Model\ClientInterface;
15
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
16
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
17
use LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUri;
18
use Symfony\Component\Validator\Constraints as Assert;
19
use LoginCidadao\OAuthBundle\Entity\Client;
20
use JMS\Serializer\Annotation as JMS;
21
use Doctrine\ORM\Mapping as ORM;
22
23
/**
24
 * @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\ClientMetadataRepository")
25
 * @UniqueEntity("client")
26
 * @UniqueEntity("client_name")
27
 * @ORM\HasLifecycleCallbacks
28
 * @ORM\Table(name="client_metadata")
29
 * @JMS\ExclusionPolicy("all")
30
 * @SectorIdentifierUri
31
 */
32
class ClientMetadata
33
{
34
    /**
35
     * @ORM\Id
36
     * @ORM\Column(type="integer")
37
     * @ORM\GeneratedValue(strategy="AUTO")
38
     */
39
    private $id;
40
    private $client_id;
41
    private $client_secret;
42
43
    /**
44
     * @var ClientInterface
45
     * @ORM\OneToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="metadata", cascade={"persist"})
46
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
47
     */
48
    private $client;
49
50
    /**
51
     * @var string[]
52
     *
53
     * @JMS\Expose
54
     * @JMS\Groups({"client_metadata"})
55
     * @Assert\All({
56
     *      @Assert\Type(type="string"),
57
     *      @Assert\NotBlank,
58
     *      @Assert\Url(checkDNS = false)
59
     * })
60
     * @ORM\Column(name="redirect_uris", type="json_array", nullable=false)
61
     */
62
    private $redirect_uris;
63
64
    /**
65
     * @var array
66
     *
67
     * @JMS\Expose
68
     * @JMS\Groups({"client_metadata"})
69
     * @Assert\All({
70
     *      @Assert\Type("string")
71
     * })
72
     * @ORM\Column(name="response_types", type="simple_array", nullable=false)
73
     */
74
    private $response_types = ['code'];
75
76
    /**
77
     * @var array
78
     *
79
     * @JMS\Expose
80
     * @JMS\Groups({"client_metadata"})
81
     * @Assert\All({
82
     *      @Assert\Type("string")
83
     * })
84
     * @ORM\Column(type="simple_array", nullable=false)
85
     */
86
    private $grant_types = ['authorization_code'];
87
88
    /**
89
     * @JMS\Expose
90
     * @JMS\Groups({"client_metadata"})
91
     * @Assert\Type(type="string")
92
     * @ORM\Column(name="application_type", type="string", length=100, nullable=false)
93
     */
94
    private $application_type = 'web';
95
96
    /**
97
     * @JMS\Expose
98
     * @JMS\Groups({"client_metadata"})
99
     * @Assert\All({
100
     *      @Assert\Type("string")
101
     * })
102
     * @ORM\Column(type="simple_array", nullable=true)
103
     */
104
    private $contacts;
105
106
    /**
107
     * @JMS\Expose
108
     * @JMS\Groups({"client_metadata"})
109
     * @Assert\Type(type="string")
110
     * @ORM\Column(type="string", nullable=true)
111
     */
112
    private $client_name;
113
114
    /**
115
     * @JMS\Expose
116
     * @JMS\Groups({"client_metadata"})
117
     * @Assert\Type(type="string")
118
     * @Assert\Url(checkDNS = false)
119
     * @ORM\Column(type="string", length=2000, nullable=true)
120
     */
121
    private $logo_uri;
122
123
    /**
124
     * @JMS\Expose
125
     * @JMS\Groups({"client_metadata"})
126
     * @Assert\Type(type="string")
127
     * @Assert\Url(checkDNS = false)
128
     * @ORM\Column(type="string", length=2000, nullable=true)
129
     */
130
    private $client_uri;
131
132
    /**
133
     * @JMS\Expose
134
     * @JMS\Groups({"client_metadata"})
135
     * @Assert\Type(type="string")
136
     * @Assert\Url(checkDNS = false)
137
     * @ORM\Column(type="string", length=2000, nullable=true)
138
     */
139
    private $policy_uri;
140
141
    /**
142
     * @JMS\Expose
143
     * @JMS\Groups({"client_metadata"})
144
     * @Assert\Url(checkDNS = false)
145
     * @Assert\Type(type="string")
146
     * @ORM\Column(type="string", length=2000, nullable=true)
147
     */
148
    private $tos_uri;
149
150
    /**
151
     * @JMS\Expose
152
     * @JMS\Groups({"client_metadata"})
153
     * @Assert\Url(checkDNS = false)
154
     * @Assert\Type(type="string")
155
     * @ORM\Column(type="string", length=2000, nullable=true)
156
     */
157
    private $jwks_uri;
158
159
    /**
160
     * @JMS\Expose
161
     * @JMS\Groups({"client_metadata"})
162
     * @Assert\Type(type="string")
163
     * @ORM\Column(type="text", nullable=true)
164
     */
165
    private $jwks;
166
167
    /**
168
     * @JMS\Expose
169
     * @JMS\Groups({"client_metadata"})
170
     * @Assert\Url(checkDNS = false, protocols = {"http", "https"})
171
     * @Assert\Type(type="string")
172
     * @ORM\Column(type="string", length=2000, nullable=true)
173
     */
174
    private $sector_identifier_uri;
175
176
    /**
177
     * @JMS\Expose
178
     * @JMS\Groups({"client_metadata"})
179
     * @Assert\Type(type="string")
180
     * @ORM\Column(type="string", length=20, nullable=false, options={"default" : "pairwise"})
181
     */
182
    private $subject_type = 'pairwise';
183
184
    /**
185
     * @JMS\Expose
186
     * @JMS\Groups({"client_metadata"})
187
     * @Assert\Type(type="string")
188
     * @ORM\Column(type="string", length=50, nullable=true)
189
     */
190
    private $id_token_signed_response_alg;
191
192
    /**
193
     * @JMS\Expose
194
     * @JMS\Groups({"client_metadata"})
195
     * @Assert\Type(type="string")
196
     * @ORM\Column(type="string", length=50, nullable=true)
197
     */
198
    private $id_token_encrypted_response_alg;
199
200
    /**
201
     * @JMS\Expose
202
     * @JMS\Groups({"client_metadata"})
203
     * @Assert\Type(type="string")
204
     * @ORM\Column(type="string", length=50, nullable=true)
205
     */
206
    private $id_token_encrypted_response_enc;
207
208
    /**
209
     * @JMS\Expose
210
     * @JMS\Groups({"client_metadata"})
211
     * @Assert\Type(type="string")
212
     * @ORM\Column(type="string", length=50, nullable=true)
213
     */
214
    private $userinfo_signed_response_alg;
215
216
    /**
217
     * @JMS\Expose
218
     * @JMS\Groups({"client_metadata"})
219
     * @Assert\Type(type="string")
220
     * @ORM\Column(type="string", length=50, nullable=true)
221
     */
222
    private $userinfo_encrypted_response_alg;
223
224
    /**
225
     * @JMS\Expose
226
     * @JMS\Groups({"client_metadata"})
227
     * @Assert\Type(type="string")
228
     * @ORM\Column(type="string", length=50, nullable=true)
229
     */
230
    private $userinfo_encrypted_response_enc;
231
232
    /**
233
     * @JMS\Expose
234
     * @JMS\Groups({"client_metadata"})
235
     * @Assert\Type(type="string")
236
     * @ORM\Column(type="string", length=50, nullable=true)
237
     */
238
    private $request_object_signing_alg;
239
240
    /**
241
     * @JMS\Expose
242
     * @JMS\Groups({"client_metadata"})
243
     * @Assert\Type(type="string")
244
     * @ORM\Column(type="string", length=50, nullable=true)
245
     */
246
    private $request_object_encryption_alg;
247
248
    /**
249
     * @JMS\Expose
250
     * @JMS\Groups({"client_metadata"})
251
     * @Assert\Type(type="string")
252
     * @ORM\Column(type="string", length=50, nullable=true)
253
     */
254
    private $request_object_encryption_enc;
255
256
    /**
257
     * @JMS\Expose
258
     * @JMS\Groups({"client_metadata"})
259
     * @Assert\Type(type="string")
260
     * @ORM\Column(type="string", length=50, nullable=true)
261
     */
262
    private $token_endpoint_auth_method;
263
264
    /**
265
     * @JMS\Expose
266
     * @JMS\Groups({"client_metadata"})
267
     * @Assert\Type(type="string")
268
     * @ORM\Column(type="string", length=50, nullable=true)
269
     */
270
    private $token_endpoint_auth_signing_alg;
271
272
    /**
273
     * @JMS\Expose
274
     * @JMS\Groups({"client_metadata"})
275
     * @Assert\Type(type="integer")
276
     * @ORM\Column(type="integer", nullable=true)
277
     */
278
    private $default_max_age;
279
280
    /**
281
     * @JMS\Expose
282
     * @JMS\Groups({"client_metadata"})
283
     * @Assert\Type(type="boolean")
284
     */
285
    private $require_auth_time = false;
286
287
    /**
288
     * @JMS\Expose
289
     * @JMS\Groups({"client_metadata"})
290
     * @Assert\Type(type="array")
291
     * @ORM\Column(type="simple_array", nullable=true)
292
     */
293
    private $default_acr_values;
294
295
    /**
296
     * @JMS\Expose
297
     * @JMS\Groups({"client_metadata"})
298
     * @Assert\Url(checkDNS = false)
299
     * @Assert\Type(type="string")
300
     * @ORM\Column(type="string", length=2000, nullable=true)
301
     */
302
    private $initiate_login_uri;
303
304
    /**
305
     * @JMS\Expose
306
     * @JMS\Groups({"client_metadata"})
307
     * @Assert\All({
308
     *      @Assert\Type("string"),
309
     *      @Assert\Url(checkDNS = false)
310
     * })
311
     * @ORM\Column(type="simple_array", nullable=true)
312
     */
313
    private $request_uris;
314
315
    /**
316
     * @JMS\Expose
317
     * @JMS\Groups({"client_metadata"})
318
     * @Assert\Type(type="string")
319
     * @ORM\Column(type="string", nullable=true)
320
     */
321
    private $registration_access_token;
322
323
    /**
324
     * @var OrganizationInterface
325
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients")
326
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
327
     */
328
    private $organization;
329
330
    /**
331
     * @JMS\Expose
332
     * @JMS\Groups({"client_metadata"})
333
     * @Assert\All({
334
     *      @Assert\Type("string"),
335
     *      @Assert\Url(checkDNS = false)
336
     * })
337
     * @ORM\Column(type="simple_array", nullable=true)
338
     */
339
    private $post_logout_redirect_uris;
340
341 22
    public function __construct()
342
    {
343 22
        $this->response_types = ['code'];
344 22
        $this->grant_types = ['authorization_code'];
345 22
        $this->application_type = 'web';
346 22
        $this->require_auth_time = false;
347 22
        $this->subject_type = 'pairwise';
348 22
    }
349
350
    /**
351
     * @param mixed $id
352
     * @return $this
353
     */
354 4
    public function setId($id)
355
    {
356 4
        $this->id = $id;
357
358 4
        return $this;
359
    }
360
361
    /**
362
     * @return string[]
363
     */
364 8
    public function getRedirectUris()
365
    {
366 8
        return $this->redirect_uris;
367
    }
368
369 5
    public function setRedirectUris($redirect_uris)
370
    {
371 5
        $this->redirect_uris = $redirect_uris;
372
373 5
        return $this;
374
    }
375
376 2
    public function getResponseTypes()
377
    {
378 2
        return $this->response_types;
379
    }
380
381 1
    public function setResponseTypes($response_types)
382
    {
383 1
        $this->response_types = $response_types;
384
385 1
        return $this;
386
    }
387
388 6
    public function getGrantTypes()
389
    {
390 6
        return $this->grant_types;
391
    }
392
393 3
    public function setGrantTypes($grant_types)
394
    {
395 3
        $this->grant_types = $grant_types;
396
397 3
        return $this;
398
    }
399
400 2
    public function getApplicationType()
401
    {
402 2
        return $this->application_type;
403
    }
404
405 1
    public function setApplicationType($application_type)
406
    {
407 1
        $this->application_type = $application_type;
408
409 1
        return $this;
410
    }
411
412 5
    public function getContacts()
413
    {
414 5
        $owners = [];
415 5
        if ($this->getClient()) {
416 2
            $owners = array_map(
417 2
                function (PersonInterface $owner) {
418 1
                    return $owner->getEmail();
419 2
                },
420 2
                $this->getClient()->getOwners()->toArray()
421
            );
422
        }
423 5
        $contacts = $this->contacts ?? [];
424
425 5
        return array_unique(array_merge($contacts, $owners));
0 ignored issues
show
Bug introduced by
It seems like $contacts can also be of type string; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

425
        return array_unique(array_merge(/** @scrutinizer ignore-type */ $contacts, $owners));
Loading history...
426
    }
427
428 3
    public function setContacts($contacts)
429
    {
430 3
        $this->contacts = $contacts;
431
432 3
        return $this;
433
    }
434
435 7
    public function getClientName()
436
    {
437 7
        return $this->client_name;
438
    }
439
440 7
    public function setClientName($client_name)
441
    {
442 7
        $this->client_name = $client_name;
443
444 7
        return $this;
445
    }
446
447 1
    public function getLogoUri()
448
    {
449 1
        return $this->logo_uri;
450
    }
451
452 1
    public function setLogoUri($logo_uri)
453
    {
454 1
        $this->logo_uri = $logo_uri;
455
456 1
        return $this;
457
    }
458
459 7
    public function getClientUri()
460
    {
461 7
        return $this->client_uri;
462
    }
463
464 5
    public function setClientUri($client_uri)
465
    {
466 5
        $this->client_uri = $client_uri;
467
468 5
        return $this;
469
    }
470
471 1
    public function getPolicyUri()
472
    {
473 1
        return $this->policy_uri;
474
    }
475
476 1
    public function setPolicyUri($policy_uri)
477
    {
478 1
        $this->policy_uri = $policy_uri;
479
480 1
        return $this;
481
    }
482
483 6
    public function getTosUri()
484
    {
485 6
        return $this->tos_uri;
486
    }
487
488 4
    public function setTosUri($tos_uri)
489
    {
490 4
        $this->tos_uri = $tos_uri;
491
492 4
        return $this;
493
    }
494
495 1
    public function getJwksUri()
496
    {
497 1
        return $this->jwks_uri;
498
    }
499
500 1
    public function setJwksUri($jwks_uri)
501
    {
502 1
        $this->jwks_uri = $jwks_uri;
503
504 1
        return $this;
505
    }
506
507 1
    public function getJwks()
508
    {
509 1
        return $this->jwks;
510
    }
511
512 1
    public function setJwks($jwks)
513
    {
514 1
        $this->jwks = $jwks;
515
516 1
        return $this;
517
    }
518
519 6
    public function getSectorIdentifierUri()
520
    {
521 6
        return $this->sector_identifier_uri;
522
    }
523
524 3
    public function setSectorIdentifierUri($sector_identifier_uri)
525
    {
526 3
        $this->sector_identifier_uri = $sector_identifier_uri;
527
528 3
        return $this;
529
    }
530
531
    /**
532
     * @return string|null
533
     */
534 3
    public function getSubjectType()
535
    {
536 3
        return $this->subject_type;
537
    }
538
539
    /**
540
     * @param string $subject_type
541
     * @return ClientMetadata
542
     */
543 1
    public function setSubjectType($subject_type)
544
    {
545 1
        $this->subject_type = $subject_type;
546
547 1
        return $this;
548
    }
549
550 2
    public function getIdTokenSignedResponseAlg()
551
    {
552 2
        return $this->id_token_signed_response_alg;
553
    }
554
555 2
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
556
    {
557 2
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
558
559 2
        return $this;
560
    }
561
562 1
    public function getIdTokenEncryptedResponseAlg()
563
    {
564 1
        return $this->id_token_encrypted_response_alg;
565
    }
566
567 1
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
568
    {
569 1
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
570
571 1
        return $this;
572
    }
573
574 1
    public function getIdTokenEncryptedResponseEnc()
575
    {
576 1
        return $this->id_token_encrypted_response_enc;
577
    }
578
579 1
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
580
    {
581 1
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
582
583 1
        return $this;
584
    }
585
586 1
    public function getUserinfoSignedResponseAlg()
587
    {
588 1
        return $this->userinfo_signed_response_alg;
589
    }
590
591 1
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
592
    {
593 1
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
594
595 1
        return $this;
596
    }
597
598 1
    public function getUserinfoEncryptedResponseAlg()
599
    {
600 1
        return $this->userinfo_encrypted_response_alg;
601
    }
602
603 1
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
604
    {
605 1
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
606
607 1
        return $this;
608
    }
609
610 1
    public function getUserinfoEncryptedResponseEnc()
611
    {
612 1
        return $this->userinfo_encrypted_response_enc;
613
    }
614
615 1
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
616
    {
617 1
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
618
619 1
        return $this;
620
    }
621
622 1
    public function getRequestObjectSigningAlg()
623
    {
624 1
        return $this->request_object_signing_alg;
625
    }
626
627 1
    public function setRequestObjectSigningAlg($request_object_signing_alg)
628
    {
629 1
        $this->request_object_signing_alg = $request_object_signing_alg;
630
631 1
        return $this;
632
    }
633
634 1
    public function getRequestObjectEncryptionAlg()
635
    {
636 1
        return $this->request_object_encryption_alg;
637
    }
638
639 1
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
640
    {
641 1
        $this->request_object_encryption_alg = $request_object_encryption_alg;
642
643 1
        return $this;
644
    }
645
646 1
    public function getRequestObjectEncryptionEnc()
647
    {
648 1
        return $this->request_object_encryption_enc;
649
    }
650
651 1
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
652
    {
653 1
        $this->request_object_encryption_enc = $request_object_encryption_enc;
654
655 1
        return $this;
656
    }
657
658 2
    public function getTokenEndpointAuthMethod()
659
    {
660 2
        return $this->token_endpoint_auth_method;
661
    }
662
663 2
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
664
    {
665 2
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
666
667 2
        return $this;
668
    }
669
670 1
    public function getTokenEndpointAuthSigningAlg()
671
    {
672 1
        return $this->token_endpoint_auth_signing_alg;
673
    }
674
675 1
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
676
    {
677 1
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
678
679 1
        return $this;
680
    }
681
682 1
    public function getDefaultMaxAge()
683
    {
684 1
        return $this->default_max_age;
685
    }
686
687 1
    public function setDefaultMaxAge($default_max_age)
688
    {
689 1
        $this->default_max_age = $default_max_age;
690
691 1
        return $this;
692
    }
693
694 2
    public function getRequireAuthTime()
695
    {
696 2
        return $this->require_auth_time;
697
    }
698
699 2
    public function setRequireAuthTime($require_auth_time)
700
    {
701 2
        $this->require_auth_time = $require_auth_time;
702
703 2
        return $this;
704
    }
705
706 1
    public function getDefaultAcrValues()
707
    {
708 1
        return $this->default_acr_values;
709
    }
710
711
    /**
712
     * @param $default_acr_values
713
     * @return ClientMetadata
714
     */
715 1
    public function setDefaultAcrValues($default_acr_values)
716
    {
717 1
        $this->default_acr_values = $default_acr_values;
718
719 1
        return $this;
720
    }
721
722 2
    public function getInitiateLoginUri()
723
    {
724 2
        return $this->initiate_login_uri;
725
    }
726
727
    /**
728
     * @param $initiate_login_uri
729
     * @return ClientMetadata
730
     */
731 2
    public function setInitiateLoginUri($initiate_login_uri)
732
    {
733 2
        $this->initiate_login_uri = $initiate_login_uri;
734
735 2
        return $this;
736
    }
737
738 1
    public function getRequestUris()
739
    {
740 1
        return $this->request_uris;
741
    }
742
743 1
    public function setRequestUris($request_uris)
744
    {
745 1
        $this->request_uris = $request_uris;
746
747 1
        return $this;
748
    }
749
750
    /**
751
     * @JMS\Groups({"client_metadata"})
752
     * @JMS\VirtualProperty
753
     * @JMS\SerializedName("client_id")
754
     */
755 3
    public function getClientId()
756
    {
757 3
        if ($this->client_id === null && $this->client) {
758 1
            return $this->client->getClientId();
759
        }
760
761 2
        return $this->client_id;
762
    }
763
764 2
    public function setClientId($client_id)
765
    {
766 2
        $this->client_id = $client_id;
767
768 2
        return $this;
769
    }
770
771
    /**
772
     * @JMS\Groups({"client_metadata"})
773
     * @JMS\VirtualProperty
774
     * @JMS\SerializedName("client_secret")
775
     */
776 3
    public function getClientSecret()
777
    {
778 3
        if ($this->client_id === null && $this->client) {
779 1
            return $this->client->getClientSecret();
780
        }
781
782 2
        return $this->client_secret;
783
    }
784
785 2
    public function setClientSecret($client_secret)
786
    {
787 2
        $this->client_secret = $client_secret;
788
789 2
        return $this;
790
    }
791
792
    /**
793
     * @param Client $client
794
     * @return ClientMetadata
795
     */
796 1
    public function fromClient(Client $client)
797
    {
798 1
        $this->setGrantTypes($client->getAllowedGrantTypes())
799 1
            ->setClientUri($client->getSiteUrl())
800 1
            ->setTosUri($client->getTermsOfUseUrl())
801 1
            ->setClientName($client->getName())
802 1
            ->setRedirectUris($client->getRedirectUris());
803
804 1
        $this->setClientId($client->getPublicId())
805 1
            ->setClientSecret($client->getSecret());
806
807 1
        return $this;
808
    }
809
810
    /**
811
     * @return Client
812
     */
813 3
    public function toClient()
814
    {
815 3
        $grantTypes = $this->getGrantTypes();
816 3
        $clientUri = $this->getClientUri();
817 3
        $tosUri = $this->getTosUri();
818 3
        $clientName = $this->getClientName();
819 3
        $redirectUris = $this->getRedirectUris();
820
821 3
        $client = new Client();
822
823 3
        if ($grantTypes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $grantTypes of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
824 3
            $client->setAllowedGrantTypes($grantTypes);
825
        }
826
827 3
        if ($clientUri) {
828 1
            $client->setLandingPageUrl($clientUri)
829 1
                ->setSiteUrl($clientUri);
830
        }
831
832 3
        if ($tosUri) {
833 1
            $client->setTermsOfUseUrl($tosUri);
834
        }
835
836 3
        if ($clientName) {
837 1
            $client->setName($clientName);
838
        }
839
840 3
        if (count($redirectUris) > 0) {
841 1
            $client->setRedirectUris($redirectUris);
842
        }
843
844 3
        $client->setVisible(false)
845 3
            ->setPublished(false);
846
847 3
        return $client;
848
    }
849
850 7
    public function getClient()
851
    {
852 7
        return $this->client;
853
    }
854
855 10
    public function setClient(ClientInterface $client)
856
    {
857 10
        $this->client = $client;
858
859 10
        return $this;
860
    }
861
862
    /**
863
     * @ORM\PrePersist()
864
     */
865 2
    public function checkDefaults()
866
    {
867 2
        $this->enforceDefaultGrantTypes();
868 2
        $this->enforceDefaultResponseTypes();
869 2
        $this->enforceDefaultApplicationType();
870 2
        $this->enforceDefaultRequireAuthTime();
871 2
        $this->enforceDefaultIdTokenSignedResponseAlg();
872 2
        $this->enforceDefaultTokenEndpointAuthMethod();
873 2
        $this->enforceValidSubjectType();
874 2
    }
875
876 2
    private function enforceDefaultGrantTypes()
877
    {
878 2
        if (!$this->getGrantTypes()) {
879 1
            $this->setGrantTypes(['authorization_code']);
880
        }
881 2
    }
882
883 2
    private function enforceDefaultResponseTypes()
884
    {
885 2
        if (!$this->getResponseTypes()) {
886 1
            $this->setResponseTypes(['code']);
887
        }
888 2
    }
889
890 2
    private function enforceDefaultApplicationType()
891
    {
892 2
        if (!$this->getApplicationType()) {
893 1
            $this->setApplicationType('web');
894
        }
895 2
    }
896
897 2
    private function enforceDefaultRequireAuthTime()
898
    {
899 2
        if (!$this->getRequireAuthTime()) {
900 2
            $this->setRequireAuthTime(false);
901
        }
902 2
    }
903
904 2
    private function enforceDefaultIdTokenSignedResponseAlg()
905
    {
906 2
        if (!$this->getIdTokenSignedResponseAlg()) {
907 2
            $this->setIdTokenSignedResponseAlg('RS256');
908
        }
909 2
    }
910
911 2
    private function enforceDefaultTokenEndpointAuthMethod()
912
    {
913 2
        if (!$this->getTokenEndpointAuthMethod()) {
914 2
            $this->setTokenEndpointAuthMethod('client_secret_basic');
915
        }
916 2
    }
917
918 2
    private function enforceValidSubjectType()
919
    {
920 2
        if (false === array_search($this->getSubjectType(), ['public', 'pairwise'])) {
921 1
            $this->setSubjectType('pairwise');
922
        }
923 2
    }
924
925 3
    public function getSectorIdentifier()
926
    {
927 3
        $siUri = $this->getSectorIdentifierUri();
928 3
        if ($siUri) {
929 1
            $uri = $siUri;
930
        } else {
931 2
            $uris = $this->getRedirectUris();
932 2
            $uri = reset($uris);
933
        }
934
935 3
        return parse_url($uri, PHP_URL_HOST);
936
    }
937
938 4
    public function getRegistrationAccessToken()
939
    {
940 4
        return $this->registration_access_token;
941
    }
942
943
    /**
944
     * @param string $registration_access_token
945
     * @return ClientMetadata
946
     */
947 4
    public function setRegistrationAccessToken($registration_access_token)
948
    {
949 4
        $this->registration_access_token = $registration_access_token;
950
951 4
        return $this;
952
    }
953
954
    /**
955
     * @return OrganizationInterface
956
     */
957 3
    public function getOrganization()
958
    {
959 3
        return $this->organization;
960
    }
961
962
    /**
963
     * @param OrganizationInterface $organization
964
     */
965 2
    public function setOrganization($organization = null)
966
    {
967 2
        $this->organization = $organization;
968 2
    }
969
970
    /**
971
     * @return array
972
     */
973 1
    public function getPostLogoutRedirectUris()
974
    {
975 1
        return array_map(
976 1
            function ($value) {
977 1
                return self::canonicalizeUri($value);
978 1
            },
979 1
            $this->post_logout_redirect_uris ?? []
0 ignored issues
show
Bug introduced by
It seems like $this->post_logout_redirect_uris ?? array() can also be of type string; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

979
            /** @scrutinizer ignore-type */ $this->post_logout_redirect_uris ?? []
Loading history...
980
        );
981
    }
982
983
    /**
984
     * @param array
985
     * @return ClientMetadata
986
     */
987 1
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
988
    {
989 1
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
990
991 1
        return $this;
992
    }
993
994
    /**
995
     * Add trailing slashes
996
     * @param $uri
997
     * @return string
998
     */
999 2
    public static function canonicalizeUri($uri)
1000
    {
1001 2
        $parsed = parse_url($uri);
1002 2
        if (array_key_exists('path', $parsed) === false) {
1003 1
            $parsed['path'] = '/';
1004
        }
1005
1006 2
        return self::unparseUrl($parsed);
1007
    }
1008
1009 2
    private static function unparseUrl($parsed_url)
1010
    {
1011 2
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
1012 2
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
1013 2
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
1014 2
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
1015 2
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
1016 2
        $pass = ($user || $pass) ? "$pass@" : '';
1017 2
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
1018 2
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
1019 2
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
1020
1021 2
        return "$scheme$user$pass$host$port$path$query$fragment";
1022
    }
1023
}
1024