Failed Conditions
Push — issue#767 ( d652de...c7fd2d )
by Guilherme
05:20
created

ClientMetadata::setOrganization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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 Doctrine\Common\Collections\ArrayCollection;
14
use LoginCidadao\CoreBundle\Model\PersonInterface;
15
use LoginCidadao\OAuthBundle\Model\ClientInterface;
16
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
17
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
18
use LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUri;
19
use Symfony\Component\Validator\Constraints as Assert;
20
use LoginCidadao\OAuthBundle\Entity\Client;
21
use JMS\Serializer\Annotation as JMS;
22
use Doctrine\ORM\Mapping as ORM;
23
24
/**
25
 * @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\ClientMetadataRepository")
26
 * @UniqueEntity("client")
27
 * @UniqueEntity("client_name")
28
 * @ORM\HasLifecycleCallbacks
29
 * @ORM\Table(name="client_metadata")
30
 * @JMS\ExclusionPolicy("all")
31
 * @SectorIdentifierUri
32
 */
33
class ClientMetadata
34
{
35
    /**
36
     * @ORM\Id
37
     * @ORM\Column(type="integer")
38
     * @ORM\GeneratedValue(strategy="AUTO")
39
     */
40
    protected $id;
41
    protected $client_id;
42
    protected $client_secret;
43
44
    /**
45
     * @var ClientInterface
46
     * @ORM\OneToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="metadata", cascade={"persist"})
47
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
48
     */
49
    protected $client;
50
51
    /**
52
     * @JMS\Expose
53
     * @JMS\Groups({"client_metadata"})
54
     * @Assert\All({
55
     *      @Assert\Type(type="string"),
56
     *      @Assert\NotBlank,
57
     *      @Assert\Url(checkDNS = false)
58
     * })
59
     * @ORM\Column(name="redirect_uris", type="json_array", nullable=false)
60
     */
61
    protected $redirect_uris;
62
63
    /**
64
     * @JMS\Expose
65
     * @JMS\Groups({"client_metadata"})
66
     * @Assert\All({
67
     *      @Assert\Type("string")
68
     * })
69
     * @ORM\Column(name="response_types", type="simple_array", nullable=false)
70
     */
71
    protected $response_types = array('code');
72
73
    /**
74
     * @JMS\Expose
75
     * @JMS\Groups({"client_metadata"})
76
     * @Assert\All({
77
     *      @Assert\Type("string")
78
     * })
79
     * @ORM\Column(type="simple_array", nullable=false)
80
     */
81
    protected $grant_types = array('authorization_code');
82
83
    /**
84
     * @JMS\Expose
85
     * @JMS\Groups({"client_metadata"})
86
     * @Assert\Type(type="string")
87
     * @ORM\Column(name="application_type", type="string", length=100, nullable=false)
88
     */
89
    protected $application_type = 'web';
90
91
    /**
92
     * @JMS\Expose
93
     * @JMS\Groups({"client_metadata"})
94
     * @Assert\All({
95
     *      @Assert\Type("string")
96
     * })
97
     * @ORM\Column(type="simple_array", nullable=true)
98
     */
99
    protected $contacts;
100
101
    /**
102
     * @JMS\Expose
103
     * @JMS\Groups({"client_metadata"})
104
     * @Assert\Type(type="string")
105
     * @ORM\Column(type="string", nullable=true)
106
     */
107
    protected $client_name;
108
109
    /**
110
     * @JMS\Expose
111
     * @JMS\Groups({"client_metadata"})
112
     * @Assert\Type(type="string")
113
     * @Assert\Url(checkDNS = false)
114
     * @ORM\Column(type="string", length=2000, nullable=true)
115
     */
116
    protected $logo_uri;
117
118
    /**
119
     * @JMS\Expose
120
     * @JMS\Groups({"client_metadata"})
121
     * @Assert\Type(type="string")
122
     * @Assert\Url(checkDNS = false)
123
     * @ORM\Column(type="string", length=2000, nullable=true)
124
     */
125
    protected $client_uri;
126
127
    /**
128
     * @JMS\Expose
129
     * @JMS\Groups({"client_metadata"})
130
     * @Assert\Type(type="string")
131
     * @Assert\Url(checkDNS = false)
132
     * @ORM\Column(type="string", length=2000, nullable=true)
133
     */
134
    protected $policy_uri;
135
136
    /**
137
     * @JMS\Expose
138
     * @JMS\Groups({"client_metadata"})
139
     * @Assert\Url(checkDNS = false)
140
     * @Assert\Type(type="string")
141
     * @ORM\Column(type="string", length=2000, nullable=true)
142
     */
143
    protected $tos_uri;
144
145
    /**
146
     * @JMS\Expose
147
     * @JMS\Groups({"client_metadata"})
148
     * @Assert\Url(checkDNS = false)
149
     * @Assert\Type(type="string")
150
     * @ORM\Column(type="string", length=2000, nullable=true)
151
     */
152
    protected $jwks_uri;
153
154
    /**
155
     * @JMS\Expose
156
     * @JMS\Groups({"client_metadata"})
157
     * @Assert\Type(type="string")
158
     * @ORM\Column(type="text", nullable=true)
159
     */
160
    protected $jwks;
161
162
    /**
163
     * @JMS\Expose
164
     * @JMS\Groups({"client_metadata"})
165
     * @Assert\Url(checkDNS = false, protocols = {"http", "https"})
166
     * @Assert\Type(type="string")
167
     * @ORM\Column(type="string", length=2000, nullable=true)
168
     */
169
    protected $sector_identifier_uri;
170
171
    /**
172
     * @JMS\Expose
173
     * @JMS\Groups({"client_metadata"})
174
     * @Assert\Type(type="string")
175
     * @ORM\Column(type="string", length=20, nullable=true)
176
     */
177
    protected $subject_type;
178
179
    /**
180
     * @JMS\Expose
181
     * @JMS\Groups({"client_metadata"})
182
     * @Assert\Type(type="string")
183
     * @ORM\Column(type="string", length=50, nullable=true)
184
     */
185
    protected $id_token_signed_response_alg;
186
187
    /**
188
     * @JMS\Expose
189
     * @JMS\Groups({"client_metadata"})
190
     * @Assert\Type(type="string")
191
     * @ORM\Column(type="string", length=50, nullable=true)
192
     */
193
    protected $id_token_encrypted_response_alg;
194
195
    /**
196
     * @JMS\Expose
197
     * @JMS\Groups({"client_metadata"})
198
     * @Assert\Type(type="string")
199
     * @ORM\Column(type="string", length=50, nullable=true)
200
     */
201
    protected $id_token_encrypted_response_enc;
202
203
    /**
204
     * @JMS\Expose
205
     * @JMS\Groups({"client_metadata"})
206
     * @Assert\Type(type="string")
207
     * @ORM\Column(type="string", length=50, nullable=true)
208
     */
209
    protected $userinfo_signed_response_alg;
210
211
    /**
212
     * @JMS\Expose
213
     * @JMS\Groups({"client_metadata"})
214
     * @Assert\Type(type="string")
215
     * @ORM\Column(type="string", length=50, nullable=true)
216
     */
217
    protected $userinfo_encrypted_response_alg;
218
219
    /**
220
     * @JMS\Expose
221
     * @JMS\Groups({"client_metadata"})
222
     * @Assert\Type(type="string")
223
     * @ORM\Column(type="string", length=50, nullable=true)
224
     */
225
    protected $userinfo_encrypted_response_enc;
226
227
    /**
228
     * @JMS\Expose
229
     * @JMS\Groups({"client_metadata"})
230
     * @Assert\Type(type="string")
231
     * @ORM\Column(type="string", length=50, nullable=true)
232
     */
233
    protected $request_object_signing_alg;
234
235
    /**
236
     * @JMS\Expose
237
     * @JMS\Groups({"client_metadata"})
238
     * @Assert\Type(type="string")
239
     * @ORM\Column(type="string", length=50, nullable=true)
240
     */
241
    protected $request_object_encryption_alg;
242
243
    /**
244
     * @JMS\Expose
245
     * @JMS\Groups({"client_metadata"})
246
     * @Assert\Type(type="string")
247
     * @ORM\Column(type="string", length=50, nullable=true)
248
     */
249
    protected $request_object_encryption_enc;
250
251
    /**
252
     * @JMS\Expose
253
     * @JMS\Groups({"client_metadata"})
254
     * @Assert\Type(type="string")
255
     * @ORM\Column(type="string", length=50, nullable=true)
256
     */
257
    protected $token_endpoint_auth_method;
258
259
    /**
260
     * @JMS\Expose
261
     * @JMS\Groups({"client_metadata"})
262
     * @Assert\Type(type="string")
263
     * @ORM\Column(type="string", length=50, nullable=true)
264
     */
265
    protected $token_endpoint_auth_signing_alg;
266
267
    /**
268
     * @JMS\Expose
269
     * @JMS\Groups({"client_metadata"})
270
     * @Assert\Type(type="integer")
271
     * @ORM\Column(type="integer", nullable=true)
272
     */
273
    protected $default_max_age;
274
275
    /**
276
     * @JMS\Expose
277
     * @JMS\Groups({"client_metadata"})
278
     * @Assert\Type(type="boolean")
279
     */
280
    protected $require_auth_time = false;
281
282
    /**
283
     * @JMS\Expose
284
     * @JMS\Groups({"client_metadata"})
285
     * @Assert\Type(type="array")
286
     * @ORM\Column(type="simple_array", nullable=true)
287
     */
288
    protected $default_acr_values;
289
290
    /**
291
     * @JMS\Expose
292
     * @JMS\Groups({"client_metadata"})
293
     * @Assert\Url(checkDNS = false)
294
     * @Assert\Type(type="string")
295
     * @ORM\Column(type="string", length=2000, nullable=true)
296
     */
297
    protected $initiate_login_uri;
298
299
    /**
300
     * @JMS\Expose
301
     * @JMS\Groups({"client_metadata"})
302
     * @Assert\All({
303
     *      @Assert\Type("string"),
304
     *      @Assert\Url(checkDNS = false)
305
     * })
306
     * @ORM\Column(type="simple_array", nullable=true)
307
     */
308
    protected $request_uris;
309
310
    /**
311
     * @JMS\Expose
312
     * @JMS\Groups({"client_metadata"})
313
     * @Assert\Type(type="string")
314
     * @ORM\Column(type="string", nullable=true)
315
     */
316
    protected $registration_access_token;
317
318
    /**
319
     * @var OrganizationInterface
320
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients")
321
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
322
     */
323
    protected $organization;
324
325
    /**
326
     * @JMS\Expose
327
     * @JMS\Groups({"client_metadata"})
328
     * @Assert\All({
329
     *      @Assert\Type("string"),
330
     *      @Assert\Url(checkDNS = false)
331
     * })
332
     * @ORM\Column(type="simple_array", nullable=true)
333
     */
334
    protected $post_logout_redirect_uris;
335
336 15
    public function __construct()
337
    {
338 15
        $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...
339 15
        $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...
340 15
        $this->application_type = 'web';
341 15
        $this->require_auth_time = false;
342 15
        $this->subject_type = 'pairwise';
343 15
    }
344
345
    /**
346
     * @param mixed $id
347
     * @return $this
348
     */
349 3
    public function setId($id)
350
    {
351 3
        $this->id = $id;
352
353 3
        return $this;
354
    }
355
356 2
    public function getRedirectUris()
357
    {
358 2
        return $this->redirect_uris;
359
    }
360
361
    public function setRedirectUris($redirect_uris)
362
    {
363
        $this->redirect_uris = $redirect_uris;
364
365
        return $this;
366
    }
367
368
    public function getResponseTypes()
369
    {
370
        return $this->response_types;
371
    }
372
373
    public function setResponseTypes($response_types)
374
    {
375
        $this->response_types = $response_types;
376
377
        return $this;
378
    }
379
380 2
    public function getGrantTypes()
381
    {
382 2
        return $this->grant_types;
383
    }
384
385
    public function setGrantTypes($grant_types)
386
    {
387
        $this->grant_types = $grant_types;
388
389
        return $this;
390
    }
391
392
    public function getApplicationType()
393
    {
394
        return $this->application_type;
395
    }
396
397
    public function setApplicationType($application_type)
398
    {
399
        $this->application_type = $application_type;
400
401
        return $this;
402
    }
403
404 3
    public function getContacts()
405
    {
406 3
        $owners = [];
407 3
        if ($this->getClient()) {
408 1
            $owners = array_map(
409
                function (PersonInterface $owner) {
410
                    return $owner->getEmail();
411 1
                },
412 1
                $this->getClient()->getOwners()->toArray()
413
            );
414
        }
415 3
        $contacts = is_array($this->contacts) ? $this->contacts : [];
0 ignored issues
show
introduced by
The condition is_array($this->contacts) is always false.
Loading history...
416
417 3
        return array_unique(array_merge($contacts, $owners));
418
    }
419
420 1
    public function setContacts($contacts)
421
    {
422 1
        $this->contacts = $contacts;
423
424 1
        return $this;
425
    }
426
427 3
    public function getClientName()
428
    {
429 3
        return $this->client_name;
430
    }
431
432 3
    public function setClientName($client_name)
433
    {
434 3
        $this->client_name = $client_name;
435
436 3
        return $this;
437
    }
438
439
    public function getLogoUri()
440
    {
441
        return $this->logo_uri;
442
    }
443
444
    public function setLogoUri($logo_uri)
445
    {
446
        $this->logo_uri = $logo_uri;
447
448
        return $this;
449
    }
450
451 2
    public function getClientUri()
452
    {
453 2
        return $this->client_uri;
454
    }
455
456
    public function setClientUri($client_uri)
457
    {
458
        $this->client_uri = $client_uri;
459
460
        return $this;
461
    }
462
463
    public function getPolicyUri()
464
    {
465
        return $this->policy_uri;
466
    }
467
468
    public function setPolicyUri($policy_uri)
469
    {
470
        $this->policy_uri = $policy_uri;
471
472
        return $this;
473
    }
474
475 2
    public function getTosUri()
476
    {
477 2
        return $this->tos_uri;
478
    }
479
480
    public function setTosUri($tos_uri)
481
    {
482
        $this->tos_uri = $tos_uri;
483
484
        return $this;
485
    }
486
487
    public function getJwksUri()
488
    {
489
        return $this->jwks_uri;
490
    }
491
492
    public function setJwksUri($jwks_uri)
493
    {
494
        $this->jwks_uri = $jwks_uri;
495
496
        return $this;
497
    }
498
499
    public function getJwks()
500
    {
501
        return $this->jwks;
502
    }
503
504
    public function setJwks($jwks)
505
    {
506
        $this->jwks = $jwks;
507
508
        return $this;
509
    }
510
511 3
    public function getSectorIdentifierUri()
512
    {
513 3
        return $this->sector_identifier_uri;
514
    }
515
516 2
    public function setSectorIdentifierUri($sector_identifier_uri)
517
    {
518 2
        $this->sector_identifier_uri = $sector_identifier_uri;
519
520 2
        return $this;
521
    }
522
523
    public function getSubjectType()
524
    {
525
        return $this->subject_type;
526
    }
527
528
    public function setSubjectType($subject_type)
529
    {
530
        $this->subject_type = $subject_type;
531
532
        return $this;
533
    }
534
535
    public function getIdTokenSignedResponseAlg()
536
    {
537
        return $this->id_token_signed_response_alg;
538
    }
539
540
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
541
    {
542
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
543
544
        return $this;
545
    }
546
547
    public function getIdTokenEncryptedResponseAlg()
548
    {
549
        return $this->id_token_encrypted_response_alg;
550
    }
551
552
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
553
    {
554
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
555
556
        return $this;
557
    }
558
559
    public function getIdTokenEncryptedResponseEnc()
560
    {
561
        return $this->id_token_encrypted_response_enc;
562
    }
563
564
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
565
    {
566
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
567
568
        return $this;
569
    }
570
571
    public function getUserinfoSignedResponseAlg()
572
    {
573
        return $this->userinfo_signed_response_alg;
574
    }
575
576
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
577
    {
578
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
579
580
        return $this;
581
    }
582
583
    public function getUserinfoEncryptedResponseAlg()
584
    {
585
        return $this->userinfo_encrypted_response_alg;
586
    }
587
588
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
589
    {
590
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
591
592
        return $this;
593
    }
594
595
    public function getUserinfoEncryptedResponseEnc()
596
    {
597
        return $this->userinfo_encrypted_response_enc;
598
    }
599
600
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
601
    {
602
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
603
604
        return $this;
605
    }
606
607
    public function getRequestObjectSigningAlg()
608
    {
609
        return $this->request_object_signing_alg;
610
    }
611
612
    public function setRequestObjectSigningAlg($request_object_signing_alg)
613
    {
614
        $this->request_object_signing_alg = $request_object_signing_alg;
615
616
        return $this;
617
    }
618
619
    public function getRequestObjectEncryptionAlg()
620
    {
621
        return $this->request_object_encryption_alg;
622
    }
623
624
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
625
    {
626
        $this->request_object_encryption_alg = $request_object_encryption_alg;
627
628
        return $this;
629
    }
630
631
    public function getRequestObjectEncryptionEnc()
632
    {
633
        return $this->request_object_encryption_enc;
634
    }
635
636
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
637
    {
638
        $this->request_object_encryption_enc = $request_object_encryption_enc;
639
640
        return $this;
641
    }
642
643
    public function getTokenEndpointAuthMethod()
644
    {
645
        return $this->token_endpoint_auth_method;
646
    }
647
648
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
649
    {
650
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
651
652
        return $this;
653
    }
654
655
    public function getTokenEndpointAuthSigningAlg()
656
    {
657
        return $this->token_endpoint_auth_signing_alg;
658
    }
659
660
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
661
    {
662
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
663
664
        return $this;
665
    }
666
667
    public function getDefaultMaxAge()
668
    {
669
        return $this->default_max_age;
670
    }
671
672
    public function setDefaultMaxAge($default_max_age)
673
    {
674
        $this->default_max_age = $default_max_age;
675
676
        return $this;
677
    }
678
679
    public function getRequireAuthTime()
680
    {
681
        return $this->require_auth_time;
682
    }
683
684
    public function setRequireAuthTime($require_auth_time)
685
    {
686
        $this->require_auth_time = $require_auth_time;
687
688
        return $this;
689
    }
690
691
    public function getDefaultAcrValues()
692
    {
693
        return $this->default_acr_values;
694
    }
695
696
    public function setDefaultAcrValues($default_acr_values)
697
    {
698
        $this->default_acr_values = $default_acr_values;
699
700
        return $this;
701
    }
702
703
    public function getInitiateLoginUri()
704
    {
705
        return $this->initiate_login_uri;
706
    }
707
708
    public function setInitiateLoginUri($initiate_login_uri)
709
    {
710
        $this->initiate_login_uri = $initiate_login_uri;
711
712
        return $this;
713
    }
714
715
    public function getRequestUris()
716
    {
717
        return $this->request_uris;
718
    }
719
720
    public function setRequestUris($request_uris)
721
    {
722
        $this->request_uris = $request_uris;
723
724
        return $this;
725
    }
726
727
    /**
728
     * @JMS\Groups({"client_metadata"})
729
     * @JMS\VirtualProperty
730
     * @JMS\SerializedName("client_id")
731
     */
732
    public function getClientId()
733
    {
734
        if ($this->client_id === null && $this->client) {
735
            return $this->client->getClientId();
736
        }
737
738
        return $this->client_id;
739
    }
740
741
    public function setClientId($client_id)
742
    {
743
        $this->client_id = $client_id;
744
745
        return $this;
746
    }
747
748
    /**
749
     * @JMS\Groups({"client_metadata"})
750
     * @JMS\VirtualProperty
751
     * @JMS\SerializedName("client_secret")
752
     */
753
    public function getClientSecret()
754
    {
755
        if ($this->client_id === null && $this->client) {
756
            return $this->client->getClientSecret();
757
        }
758
759
        return $this->client_secret;
760
    }
761
762
    public function setClientSecret($client_secret)
763
    {
764
        $this->client_secret = $client_secret;
765
766
        return $this;
767
    }
768
769
    /**
770
     * @param Client $client
771
     * @return ClientMetadata
772
     */
773
    public function fromClient(Client $client)
774
    {
775
        $this->setGrantTypes($client->getAllowedGrantTypes())
776
            ->setClientUri($client->getSiteUrl())
777
            ->setTosUri($client->getTermsOfUseUrl())
778
            ->setClientName($client->getName())
779
            ->setRedirectUris($client->getRedirectUris());
780
781
        $this->setClientId($client->getPublicId())
782
            ->setClientSecret($client->getSecret());
783
784
        return $this;
785
    }
786
787
    /**
788
     * @return Client
789
     */
790 2
    public function toClient()
791
    {
792 2
        $grantTypes = $this->getGrantTypes();
793 2
        $clientUri = $this->getClientUri();
794 2
        $tosUri = $this->getTosUri();
795 2
        $clientName = $this->getClientName();
796 2
        $redirectUris = $this->getRedirectUris();
797
798 2
        $client = new Client();
799
800 2
        if ($grantTypes) {
801 2
            $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

801
            $client->setAllowedGrantTypes(/** @scrutinizer ignore-type */ $grantTypes);
Loading history...
802
        }
803
804 2
        if ($clientUri) {
805
            $client->setLandingPageUrl($clientUri)
806
                ->setSiteUrl($clientUri);
807
        }
808
809 2
        if ($tosUri) {
810
            $client->setTermsOfUseUrl($tosUri);
811
        }
812
813 2
        if ($clientName) {
814
            $client->setName($clientName);
815
        }
816
817 2
        if ($redirectUris) {
818
            $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

818
            $client->setRedirectUris(/** @scrutinizer ignore-type */ $redirectUris);
Loading history...
819
        }
820
821 2
        $client->setVisible(false)
822 2
            ->setPublished(false);
823
824 2
        return $client;
825
    }
826
827 4
    public function getClient()
828
    {
829 4
        return $this->client;
830
    }
831
832 7
    public function setClient(ClientInterface $client)
833
    {
834 7
        $this->client = $client;
835
836 7
        return $this;
837
    }
838
839
    /**
840
     * @ORM\PrePersist()
841
     */
842
    public function checkDefaults()
843
    {
844
        if (!$this->getGrantTypes()) {
845
            $this->setGrantTypes(array('authorization_code'));
846
        }
847
848
        if (!$this->getResponseTypes()) {
849
            $this->setResponseTypes(array('code'));
850
        }
851
852
        if (!$this->getApplicationType()) {
853
            $this->setApplicationType('web');
854
        }
855
856
        if (!$this->getRequireAuthTime()) {
857
            $this->setRequireAuthTime(false);
858
        }
859
860
        if (!$this->getIdTokenSignedResponseAlg()) {
861
            $this->setIdTokenSignedResponseAlg('RS256');
862
        }
863
864
        if (!$this->getTokenEndpointAuthMethod()) {
865
            $this->setTokenEndpointAuthMethod('client_secret_basic');
866
        }
867
    }
868
869
    public function getSectorIdentifier()
870
    {
871
        $siUri = $this->getSectorIdentifierUri();
872
        if ($siUri) {
873
            $uri = $siUri;
874
        } else {
875
            $uris = $this->getRedirectUris();
876
            $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

876
            $uri = reset(/** @scrutinizer ignore-type */ $uris);
Loading history...
877
        }
878
879
        return parse_url($uri, PHP_URL_HOST);
880
    }
881
882
    public function getRegistrationAccessToken()
883
    {
884
        return $this->registration_access_token;
885
    }
886
887
    /**
888
     * @return OrganizationInterface
889
     */
890 3
    public function getOrganization()
891
    {
892 3
        return $this->organization;
893
    }
894
895
    /**
896
     * @param OrganizationInterface $organization
897
     */
898 2
    public function setOrganization($organization = null)
899
    {
900 2
        $this->organization = $organization;
901 2
    }
902
903
    /**
904
     * @return array
905
     */
906
    public function getPostLogoutRedirectUris()
907
    {
908
        return array_map(
909
            function ($value) {
910
                return self::canonicalizeUri($value);
911
            },
912
            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) is always false.
Loading history...
913
        );
914
    }
915
916
    /**
917
     * @param array
918
     * @return ClientMetadata
919
     */
920
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
921
    {
922
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
923
924
        return $this;
925
    }
926
927
    /**
928
     * Add trailing slashes
929
     */
930
    public static function canonicalizeUri($uri)
931
    {
932
        $parsed = parse_url($uri);
933
        if (array_key_exists('path', $parsed) === false) {
934
            $parsed['path'] = '/';
935
        }
936
        $unparsed = self::unparseUrl($parsed);
937
938
        return $unparsed;
939
    }
940
941
    private static function unparseUrl($parsed_url)
942
    {
943
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
944
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
945
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
946
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
947
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
948
        $pass = ($user || $pass) ? "$pass@" : '';
949
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
950
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
951
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment']
952
            : '';
953
954
        return "$scheme$user$pass$host$port$path$query$fragment";
955
    }
956
}
957