Completed
Push — release-2.x ( c278f6...ea9a53 )
by Nic
04:03
created

DuplicateIdentityException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A forBootstrappingWithYubikeySecondFactor() 0 10 1
1
<?php
2
/**
3
 * Copyright 2017 SURFnet bv
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\CommandHandler\Exception;
19
20
use Exception;
21
use RuntimeException;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\Stepup\Identity\Value\NameId;
24
25
final class DuplicateIdentityException extends RuntimeException
26
{
27
    public function __construct($message = "", $code = 0, Exception $previous = null)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
28
    {
29
        parent::__construct($message, $code, $previous);
30
    }
31
32
    /**
33
     * @param NameId $nameId
34
     * @param Institution $institution
35
     *
36
     * @return DuplicateIdentityException
37
     */
38
    public static function forBootstrappingWithYubikeySecondFactor(NameId $nameId, Institution $institution)
39
    {
40
        return new self(
41
            sprintf(
42
                'Trying to bootstrap a duplicate identity: an identity with name ID "%s" from institution "%s" already exists.',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
                $nameId->getNameId(),
44
                $institution->getInstitution()
45
            )
46
        );
47
    }
48
}
49