Failed Conditions
Push — issue#666 ( 82e9d5...91903a )
by Guilherme
08:00
created

ClientMetadata::canonicalizeUri()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 9.6666
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\OrganizationInterface;
15
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
16
use LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUri;
17
use Symfony\Component\Validator\Constraints as Assert;
18
use LoginCidadao\OAuthBundle\Entity\Client;
19
use JMS\Serializer\Annotation as JMS;
20
use Doctrine\ORM\Mapping as ORM;
21
22
/**
23
 * @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\ClientMetadataRepository")
24
 * @UniqueEntity("client")
25
 * @UniqueEntity("client_name")
26
 * @ORM\HasLifecycleCallbacks
27
 * @ORM\Table(name="client_metadata")
28
 * @JMS\ExclusionPolicy("all")
29
 * @SectorIdentifierUri
30
 */
31
class ClientMetadata
32
{
33
    /**
34
     * @ORM\Id
35
     * @ORM\Column(type="integer")
36
     * @ORM\GeneratedValue(strategy="AUTO")
37
     */
38
    protected $id;
39
    protected $client_id;
40
    protected $client_secret;
41
42
    /**
43
     * @var Client
44
     * @ORM\OneToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="metadata", cascade={"persist"})
45
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
46
     */
47
    protected $client;
48
49
    /**
50
     * @JMS\Expose
51
     * @JMS\Groups({"client_metadata"})
52
     * @Assert\All({
53
     *      @Assert\Type(type="string"),
54
     *      @Assert\NotBlank,
55
     *      @Assert\Url(checkDNS = false)
56
     * })
57
     * @ORM\Column(name="redirect_uris", type="json_array", nullable=false)
58
     */
59
    protected $redirect_uris;
60
61
    /**
62
     * @JMS\Expose
63
     * @JMS\Groups({"client_metadata"})
64
     * @Assert\All({
65
     *      @Assert\Type("string")
66
     * })
67
     * @ORM\Column(name="response_types", type="simple_array", nullable=false)
68
     */
69
    protected $response_types = array('code');
70
71
    /**
72
     * @JMS\Expose
73
     * @JMS\Groups({"client_metadata"})
74
     * @Assert\All({
75
     *      @Assert\Type("string")
76
     * })
77
     * @ORM\Column(type="simple_array", nullable=false)
78
     */
79
    protected $grant_types = array('authorization_code');
80
81
    /**
82
     * @JMS\Expose
83
     * @JMS\Groups({"client_metadata"})
84
     * @Assert\Type(type="string")
85
     * @ORM\Column(name="application_type", type="string", length=100, nullable=false)
86
     */
87
    protected $application_type = 'web';
88
89
    /**
90
     * @JMS\Expose
91
     * @JMS\Groups({"client_metadata"})
92
     * @Assert\All({
93
     *      @Assert\Type("string")
94
     * })
95
     * @ORM\Column(type="simple_array", nullable=true)
96
     */
97
    protected $contacts;
98
99
    /**
100
     * @JMS\Expose
101
     * @JMS\Groups({"client_metadata"})
102
     * @Assert\Type(type="string")
103
     * @ORM\Column(type="string", nullable=true)
104
     */
105
    protected $client_name;
106
107
    /**
108
     * @JMS\Expose
109
     * @JMS\Groups({"client_metadata"})
110
     * @Assert\Type(type="string")
111
     * @Assert\Url(checkDNS = false)
112
     * @ORM\Column(type="string", length=2000, nullable=true)
113
     */
114
    protected $logo_uri;
115
116
    /**
117
     * @JMS\Expose
118
     * @JMS\Groups({"client_metadata"})
119
     * @Assert\Type(type="string")
120
     * @Assert\Url(checkDNS = false)
121
     * @ORM\Column(type="string", length=2000, nullable=true)
122
     */
123
    protected $client_uri;
124
125
    /**
126
     * @JMS\Expose
127
     * @JMS\Groups({"client_metadata"})
128
     * @Assert\Type(type="string")
129
     * @Assert\Url(checkDNS = false)
130
     * @ORM\Column(type="string", length=2000, nullable=true)
131
     */
132
    protected $policy_uri;
133
134
    /**
135
     * @JMS\Expose
136
     * @JMS\Groups({"client_metadata"})
137
     * @Assert\Url(checkDNS = false)
138
     * @Assert\Type(type="string")
139
     * @ORM\Column(type="string", length=2000, nullable=true)
140
     */
141
    protected $tos_uri;
142
143
    /**
144
     * @JMS\Expose
145
     * @JMS\Groups({"client_metadata"})
146
     * @Assert\Url(checkDNS = false)
147
     * @Assert\Type(type="string")
148
     * @ORM\Column(type="string", length=2000, nullable=true)
149
     */
150
    protected $jwks_uri;
151
152
    /**
153
     * @JMS\Expose
154
     * @JMS\Groups({"client_metadata"})
155
     * @Assert\Type(type="string")
156
     * @ORM\Column(type="text", nullable=true)
157
     */
158
    protected $jwks;
159
160
    /**
161
     * @JMS\Expose
162
     * @JMS\Groups({"client_metadata"})
163
     * @Assert\Url(checkDNS = false, protocols = {"http", "https"})
164
     * @Assert\Type(type="string")
165
     * @ORM\Column(type="string", length=2000, nullable=true)
166
     */
167
    protected $sector_identifier_uri;
168
169
    /**
170
     * @JMS\Expose
171
     * @JMS\Groups({"client_metadata"})
172
     * @Assert\Type(type="string")
173
     * @ORM\Column(type="string", length=20, nullable=true)
174
     */
175
    protected $subject_type;
176
177
    /**
178
     * @JMS\Expose
179
     * @JMS\Groups({"client_metadata"})
180
     * @Assert\Type(type="string")
181
     * @ORM\Column(type="string", length=50, nullable=true)
182
     */
183
    protected $id_token_signed_response_alg;
184
185
    /**
186
     * @JMS\Expose
187
     * @JMS\Groups({"client_metadata"})
188
     * @Assert\Type(type="string")
189
     * @ORM\Column(type="string", length=50, nullable=true)
190
     */
191
    protected $id_token_encrypted_response_alg;
192
193
    /**
194
     * @JMS\Expose
195
     * @JMS\Groups({"client_metadata"})
196
     * @Assert\Type(type="string")
197
     * @ORM\Column(type="string", length=50, nullable=true)
198
     */
199
    protected $id_token_encrypted_response_enc;
200
201
    /**
202
     * @JMS\Expose
203
     * @JMS\Groups({"client_metadata"})
204
     * @Assert\Type(type="string")
205
     * @ORM\Column(type="string", length=50, nullable=true)
206
     */
207
    protected $userinfo_signed_response_alg;
208
209
    /**
210
     * @JMS\Expose
211
     * @JMS\Groups({"client_metadata"})
212
     * @Assert\Type(type="string")
213
     * @ORM\Column(type="string", length=50, nullable=true)
214
     */
215
    protected $userinfo_encrypted_response_alg;
216
217
    /**
218
     * @JMS\Expose
219
     * @JMS\Groups({"client_metadata"})
220
     * @Assert\Type(type="string")
221
     * @ORM\Column(type="string", length=50, nullable=true)
222
     */
223
    protected $userinfo_encrypted_response_enc;
224
225
    /**
226
     * @JMS\Expose
227
     * @JMS\Groups({"client_metadata"})
228
     * @Assert\Type(type="string")
229
     * @ORM\Column(type="string", length=50, nullable=true)
230
     */
231
    protected $request_object_signing_alg;
232
233
    /**
234
     * @JMS\Expose
235
     * @JMS\Groups({"client_metadata"})
236
     * @Assert\Type(type="string")
237
     * @ORM\Column(type="string", length=50, nullable=true)
238
     */
239
    protected $request_object_encryption_alg;
240
241
    /**
242
     * @JMS\Expose
243
     * @JMS\Groups({"client_metadata"})
244
     * @Assert\Type(type="string")
245
     * @ORM\Column(type="string", length=50, nullable=true)
246
     */
247
    protected $request_object_encryption_enc;
248
249
    /**
250
     * @JMS\Expose
251
     * @JMS\Groups({"client_metadata"})
252
     * @Assert\Type(type="string")
253
     * @ORM\Column(type="string", length=50, nullable=true)
254
     */
255
    protected $token_endpoint_auth_method;
256
257
    /**
258
     * @JMS\Expose
259
     * @JMS\Groups({"client_metadata"})
260
     * @Assert\Type(type="string")
261
     * @ORM\Column(type="string", length=50, nullable=true)
262
     */
263
    protected $token_endpoint_auth_signing_alg;
264
265
    /**
266
     * @JMS\Expose
267
     * @JMS\Groups({"client_metadata"})
268
     * @Assert\Type(type="integer")
269
     * @ORM\Column(type="integer", nullable=true)
270
     */
271
    protected $default_max_age;
272
273
    /**
274
     * @JMS\Expose
275
     * @JMS\Groups({"client_metadata"})
276
     * @Assert\Type(type="boolean")
277
     */
278
    protected $require_auth_time = false;
279
280
    /**
281
     * @JMS\Expose
282
     * @JMS\Groups({"client_metadata"})
283
     * @Assert\Type(type="array")
284
     * @ORM\Column(type="simple_array", nullable=true)
285
     */
286
    protected $default_acr_values;
287
288
    /**
289
     * @JMS\Expose
290
     * @JMS\Groups({"client_metadata"})
291
     * @Assert\Url(checkDNS = false)
292
     * @Assert\Type(type="string")
293
     * @ORM\Column(type="string", length=2000, nullable=true)
294
     */
295
    protected $initiate_login_uri;
296
297
    /**
298
     * @JMS\Expose
299
     * @JMS\Groups({"client_metadata"})
300
     * @Assert\All({
301
     *      @Assert\Type("string"),
302
     *      @Assert\Url(checkDNS = false)
303
     * })
304
     * @ORM\Column(type="simple_array", nullable=true)
305
     */
306
    protected $request_uris;
307
308
    /**
309
     * @JMS\Expose
310
     * @JMS\Groups({"client_metadata"})
311
     * @Assert\Type(type="string")
312
     * @ORM\Column(type="string", nullable=true)
313
     */
314
    protected $registration_access_token;
315
316
    /**
317
     * @var OrganizationInterface
318
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients")
319
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
320
     */
321
    protected $organization;
322
323
    /**
324
     * @JMS\Expose
325
     * @JMS\Groups({"client_metadata"})
326
     * @Assert\All({
327
     *      @Assert\Type("string"),
328
     *      @Assert\Url(checkDNS = false)
329
     * })
330
     * @ORM\Column(type="simple_array", nullable=true)
331
     */
332
    protected $post_logout_redirect_uris;
333
334 16
    public function __construct()
335
    {
336 16
        $this->response_types = array('code');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('code') of type array<integer,string> is incompatible with the declared type string of property $response_types.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
337 16
        $this->grant_types = array('authorization_code');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('authorization_code') of type array<integer,string> is incompatible with the declared type string of property $grant_types.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
338 16
        $this->application_type = 'web';
339 16
        $this->require_auth_time = false;
340 16
        $this->subject_type = 'pairwise';
341 16
    }
342
343 4
    public function getRedirectUris()
344
    {
345 4
        return $this->redirect_uris;
346
    }
347
348 4
    public function setRedirectUris($redirect_uris)
349
    {
350 4
        $this->redirect_uris = $redirect_uris;
351
352 4
        return $this;
353
    }
354
355 3
    public function getResponseTypes()
356
    {
357 3
        return $this->response_types;
358
    }
359
360 3
    public function setResponseTypes($response_types)
361
    {
362 3
        $this->response_types = $response_types;
363
364 3
        return $this;
365
    }
366
367 4
    public function getGrantTypes()
368
    {
369 4
        return $this->grant_types;
370
    }
371
372 4
    public function setGrantTypes($grant_types)
373
    {
374 4
        $this->grant_types = $grant_types;
375
376 4
        return $this;
377
    }
378
379 3
    public function getApplicationType()
380
    {
381 3
        return $this->application_type;
382
    }
383
384 3
    public function setApplicationType($application_type)
385
    {
386 3
        $this->application_type = $application_type;
387
388 3
        return $this;
389
    }
390
391 4
    public function getContacts()
392
    {
393 4
        $owners = [];
394 4
        if ($this->getClient()) {
395
            $owners = array_map(
396
                function (PersonInterface $owner) {
397
                    return $owner->getEmail();
398
                },
399
                $this->getClient()->getOwners()->toArray()
400
            );
401
        }
402 4
        $contacts = is_array($this->contacts) ? $this->contacts : [];
0 ignored issues
show
introduced by
The condition is_array($this->contacts) can never be true.
Loading history...
403
404 4
        return array_unique(array_merge($contacts, $owners));
405
    }
406
407 4
    public function setContacts($contacts)
408
    {
409 4
        $this->contacts = $contacts;
410
411 4
        return $this;
412
    }
413
414 5
    public function getClientName()
415
    {
416 5
        return $this->client_name;
417
    }
418
419 3
    public function setClientName($client_name)
420
    {
421 3
        $this->client_name = $client_name;
422
423 3
        return $this;
424
    }
425
426 3
    public function getLogoUri()
427
    {
428 3
        return $this->logo_uri;
429
    }
430
431 1
    public function setLogoUri($logo_uri)
432
    {
433 1
        $this->logo_uri = $logo_uri;
434
435 1
        return $this;
436
    }
437
438 4
    public function getClientUri()
439
    {
440 4
        return $this->client_uri;
441
    }
442
443 2
    public function setClientUri($client_uri)
444
    {
445 2
        $this->client_uri = $client_uri;
446
447 2
        return $this;
448
    }
449
450 3
    public function getPolicyUri()
451
    {
452 3
        return $this->policy_uri;
453
    }
454
455
    public function setPolicyUri($policy_uri)
456
    {
457
        $this->policy_uri = $policy_uri;
458
459
        return $this;
460
    }
461
462 4
    public function getTosUri()
463
    {
464 4
        return $this->tos_uri;
465
    }
466
467 2
    public function setTosUri($tos_uri)
468
    {
469 2
        $this->tos_uri = $tos_uri;
470
471 2
        return $this;
472
    }
473
474 3
    public function getJwksUri()
475
    {
476 3
        return $this->jwks_uri;
477
    }
478
479
    public function setJwksUri($jwks_uri)
480
    {
481
        $this->jwks_uri = $jwks_uri;
482
483
        return $this;
484
    }
485
486 3
    public function getJwks()
487
    {
488 3
        return $this->jwks;
489
    }
490
491
    public function setJwks($jwks)
492
    {
493
        $this->jwks = $jwks;
494
495
        return $this;
496
    }
497
498 3
    public function getSectorIdentifierUri()
499
    {
500 3
        return $this->sector_identifier_uri;
501
    }
502
503
    public function setSectorIdentifierUri($sector_identifier_uri)
504
    {
505
        $this->sector_identifier_uri = $sector_identifier_uri;
506
507
        return $this;
508
    }
509
510 3
    public function getSubjectType()
511
    {
512 3
        return $this->subject_type;
513
    }
514
515 3
    public function setSubjectType($subject_type)
516
    {
517 3
        $this->subject_type = $subject_type;
518
519 3
        return $this;
520
    }
521
522 3
    public function getIdTokenSignedResponseAlg()
523
    {
524 3
        return $this->id_token_signed_response_alg;
525
    }
526
527 1
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
528
    {
529 1
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
530
531 1
        return $this;
532
    }
533
534 3
    public function getIdTokenEncryptedResponseAlg()
535
    {
536 3
        return $this->id_token_encrypted_response_alg;
537
    }
538
539
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
540
    {
541
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
542
543
        return $this;
544
    }
545
546 3
    public function getIdTokenEncryptedResponseEnc()
547
    {
548 3
        return $this->id_token_encrypted_response_enc;
549
    }
550
551
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
552
    {
553
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
554
555
        return $this;
556
    }
557
558 3
    public function getUserinfoSignedResponseAlg()
559
    {
560 3
        return $this->userinfo_signed_response_alg;
561
    }
562
563
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
564
    {
565
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
566
567
        return $this;
568
    }
569
570 3
    public function getUserinfoEncryptedResponseAlg()
571
    {
572 3
        return $this->userinfo_encrypted_response_alg;
573
    }
574
575
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
576
    {
577
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
578
579
        return $this;
580
    }
581
582 3
    public function getUserinfoEncryptedResponseEnc()
583
    {
584 3
        return $this->userinfo_encrypted_response_enc;
585
    }
586
587
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
588
    {
589
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
590
591
        return $this;
592
    }
593
594 3
    public function getRequestObjectSigningAlg()
595
    {
596 3
        return $this->request_object_signing_alg;
597
    }
598
599
    public function setRequestObjectSigningAlg($request_object_signing_alg)
600
    {
601
        $this->request_object_signing_alg = $request_object_signing_alg;
602
603
        return $this;
604
    }
605
606 3
    public function getRequestObjectEncryptionAlg()
607
    {
608 3
        return $this->request_object_encryption_alg;
609
    }
610
611
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
612
    {
613
        $this->request_object_encryption_alg = $request_object_encryption_alg;
614
615
        return $this;
616
    }
617
618 3
    public function getRequestObjectEncryptionEnc()
619
    {
620 3
        return $this->request_object_encryption_enc;
621
    }
622
623
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
624
    {
625
        $this->request_object_encryption_enc = $request_object_encryption_enc;
626
627
        return $this;
628
    }
629
630 3
    public function getTokenEndpointAuthMethod()
631
    {
632 3
        return $this->token_endpoint_auth_method;
633
    }
634
635 1
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
636
    {
637 1
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
638
639 1
        return $this;
640
    }
641
642 3
    public function getTokenEndpointAuthSigningAlg()
643
    {
644 3
        return $this->token_endpoint_auth_signing_alg;
645
    }
646
647
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
648
    {
649
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
650
651
        return $this;
652
    }
653
654 3
    public function getDefaultMaxAge()
655
    {
656 3
        return $this->default_max_age;
657
    }
658
659
    public function setDefaultMaxAge($default_max_age)
660
    {
661
        $this->default_max_age = $default_max_age;
662
663
        return $this;
664
    }
665
666 3
    public function getRequireAuthTime()
667
    {
668 3
        return $this->require_auth_time;
669
    }
670
671 1
    public function setRequireAuthTime($require_auth_time)
672
    {
673 1
        $this->require_auth_time = $require_auth_time;
674
675 1
        return $this;
676
    }
677
678 3
    public function getDefaultAcrValues()
679
    {
680 3
        return $this->default_acr_values;
681
    }
682
683 3
    public function setDefaultAcrValues($default_acr_values)
684
    {
685 3
        $this->default_acr_values = $default_acr_values;
686
687 3
        return $this;
688
    }
689
690 4
    public function getInitiateLoginUri()
691
    {
692 4
        return $this->initiate_login_uri;
693
    }
694
695 1
    public function setInitiateLoginUri($initiate_login_uri)
696
    {
697 1
        $this->initiate_login_uri = $initiate_login_uri;
698
699 1
        return $this;
700
    }
701
702 3
    public function getRequestUris()
703
    {
704 3
        return $this->request_uris;
705
    }
706
707
    public function setRequestUris($request_uris)
708
    {
709
        $this->request_uris = $request_uris;
710
711
        return $this;
712
    }
713
714
    /**
715
     * @JMS\Groups({"client_metadata"})
716
     * @JMS\VirtualProperty
717
     * @JMS\SerializedName("client_id")
718
     */
719 3
    public function getClientId()
720
    {
721 3
        if ($this->client_id === null && $this->client) {
722
            return $this->client->getClientId();
723
        }
724
725 3
        return $this->client_id;
726
    }
727
728 1
    public function setClientId($client_id)
729
    {
730 1
        $this->client_id = $client_id;
731
732 1
        return $this;
733
    }
734
735
    /**
736
     * @JMS\Groups({"client_metadata"})
737
     * @JMS\VirtualProperty
738
     * @JMS\SerializedName("client_secret")
739
     */
740 3
    public function getClientSecret()
741
    {
742 3
        if ($this->client_id === null && $this->client) {
743
            return $this->client->getClientSecret();
744
        }
745
746 3
        return $this->client_secret;
747
    }
748
749 1
    public function setClientSecret($client_secret)
750
    {
751 1
        $this->client_secret = $client_secret;
752
753 1
        return $this;
754
    }
755
756
    /**
757
     * @param Client $client
758
     * @return ClientMetadata
759
     */
760 1
    public function fromClient(Client $client)
761
    {
762 1
        $this->setGrantTypes($client->getAllowedGrantTypes())
763 1
            ->setClientUri($client->getSiteUrl())
764 1
            ->setTosUri($client->getTermsOfUseUrl())
765 1
            ->setClientName($client->getName())
766 1
            ->setRedirectUris($client->getRedirectUris());
767
768 1
        $this->setClientId($client->getPublicId())
769 1
            ->setClientSecret($client->getSecret());
770
771 1
        return $this;
772
    }
773
774
    /**
775
     * @return Client
776
     */
777 1
    public function toClient()
778
    {
779 1
        $name = $this->getClientName();
780 1
        $hasName = $name !== null && strlen($name) > 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $hasName is dead and can be removed.
Loading history...
781
782 1
        $grantTypes = $this->getGrantTypes();
783 1
        $clientUri = $this->getClientUri();
784 1
        $tosUri = $this->getTosUri();
785 1
        $clientName = $this->getClientName();
786 1
        $redirectUris = $this->getRedirectUris();
787
788 1
        $client = new Client();
789
790 1
        if ($grantTypes) {
791
            $client->setAllowedGrantTypes($grantTypes);
0 ignored issues
show
Bug introduced by
$grantTypes of type string is incompatible with the type array expected by parameter $grantTypes of FOS\OAuthServerBundle\Mo...:setAllowedGrantTypes(). ( Ignorable by Annotation )

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

791
            $client->setAllowedGrantTypes(/** @scrutinizer ignore-type */ $grantTypes);
Loading history...
792
        }
793
794 1
        if ($clientUri) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $clientUri of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
795
            $client->setLandingPageUrl($clientUri)
796
                ->setSiteUrl($clientUri);
797
        }
798
799 1
        if ($tosUri) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $tosUri of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
800
            $client->setTermsOfUseUrl($tosUri);
801
        }
802
803 1
        if ($clientName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $clientName of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
804
            $client->setName($clientName);
805
        }
806
807 1
        if ($redirectUris) {
808 1
            $client->setRedirectUris($redirectUris);
0 ignored issues
show
Bug introduced by
$redirectUris of type string is incompatible with the type array expected by parameter $redirectUris of LoginCidadao\OAuthBundle...ient::setRedirectUris(). ( Ignorable by Annotation )

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

808
            $client->setRedirectUris(/** @scrutinizer ignore-type */ $redirectUris);
Loading history...
809
        }
810
811 1
        $client->setVisible(false)
812 1
            ->setPublished(false);
813
814 1
        return $client;
815
    }
816
817 4
    public function getClient()
818
    {
819 4
        return $this->client;
820
    }
821
822 3
    public function setClient(Client $client)
823
    {
824 3
        $this->client = $client;
825
826 3
        return $this;
827
    }
828
829
    /**
830
     * @ORM\PrePersist()
831
     */
832 1
    public function checkDefaults()
833
    {
834 1
        if (!$this->getGrantTypes()) {
835 1
            $this->setGrantTypes(array('authorization_code'));
836
        }
837
838 1
        if (!$this->getResponseTypes()) {
839 1
            $this->setResponseTypes(array('code'));
840
        }
841
842 1
        if (!$this->getApplicationType()) {
843 1
            $this->setApplicationType('web');
844
        }
845
846 1
        if (!$this->getRequireAuthTime()) {
847 1
            $this->setRequireAuthTime(false);
848
        }
849
850 1
        if (!$this->getIdTokenSignedResponseAlg()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getIdTokenSignedResponseAlg() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
851 1
            $this->setIdTokenSignedResponseAlg('RS256');
852
        }
853
854 1
        if (!$this->getTokenEndpointAuthMethod()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getTokenEndpointAuthMethod() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
855 1
            $this->setTokenEndpointAuthMethod('client_secret_basic');
856
        }
857 1
    }
858
859
    public function getSectorIdentifier()
860
    {
861
        $siUri = $this->getSectorIdentifierUri();
862
        if ($siUri) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $siUri of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
863
            $uri = $siUri;
864
        } else {
865
            $uris = $this->getRedirectUris();
866
            $uri = reset($uris);
0 ignored issues
show
Bug introduced by
$uris of type string is incompatible with the type array expected by parameter $array of reset(). ( Ignorable by Annotation )

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

866
            $uri = reset(/** @scrutinizer ignore-type */ $uris);
Loading history...
867
        }
868
869
        return parse_url($uri, PHP_URL_HOST);
870
    }
871
872
    public function getRegistrationAccessToken()
873
    {
874
        return $this->registration_access_token;
875
    }
876
877
    /**
878
     * @return OrganizationInterface
879
     */
880
    public function getOrganization()
881
    {
882
        return $this->organization;
883
    }
884
885
    /**
886
     * @param OrganizationInterface $organization
887
     */
888
    public function setOrganization($organization = null)
889
    {
890
        $this->organization = $organization;
891
    }
892
893
    /**
894
     * @return array
895
     */
896 3
    public function getPostLogoutRedirectUris()
897
    {
898 3
        return array_map(
899 3
            function ($value) {
900
                return self::canonicalizeUri($value);
901 3
            },
902 3
            is_array($this->post_logout_redirect_uris) ? $this->post_logout_redirect_uris : []
0 ignored issues
show
introduced by
The condition is_array($this->post_logout_redirect_uris) can never be true.
Loading history...
903
        );
904
    }
905
906
    /**
907
     * @param array
908
     * @return ClientMetadata
909
     */
910 3
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
911
    {
912 3
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
913
914 3
        return $this;
915
    }
916
917
    /**
918
     * Add trailing slashes
919
     */
920
    public static function canonicalizeUri($uri)
921
    {
922
        $parsed = parse_url($uri);
923
        if (array_key_exists('path', $parsed) === false) {
924
            $parsed['path'] = '/';
925
        }
926
        $unparsed = self::unparseUrl($parsed);
927
928
        return $unparsed;
929
    }
930
931
    private static function unparseUrl($parsed_url)
932
    {
933
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
934
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
935
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
936
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
937
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
938
        $pass = ($user || $pass) ? "$pass@" : '';
939
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
940
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
941
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment']
942
            : '';
943
944
        return "$scheme$user$pass$host$port$path$query$fragment";
945
    }
946
}
947