FirstClass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 61.36 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 27
loc 44
ccs 22
cts 22
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decodeString() 13 13 3
A encodeString() 13 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * File containing FirstClass
4
 *
5
 * @package conquerorsoft/my_first_library
6
 * @author Christian Varela <[email protected]>
7
 * @copyright (c) 2017, Conqueror Soft Inc (http://www.conquerorsoft.com)
8
 */
9
10
namespace conquerorsoft\my_first_library;
11
12
/**
13
 * This class provides functionality for encoding and decoding alphanumerical strings including spaces
14
 * Other characters will throw an exception
15
 *
16
 * @author Christian Varela <[email protected]>
17
 */
18
class FirstClass
19
{
20
    /**
21
     * Encodes a string by a simple shift of characters
22
     *
23
     * @param string $string
24
     * @return string
25
     * @throws \Exception
26
     */
27 18 View Code Duplication
    public function encodeString($string)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29 18
        $string=strtolower($string);
30 18
        $src="abcdefghijklmnopqrstuvwxyz0123456789 ";
31 18
        $dst="jklmnopqrstuvwxyz0123456789abcdefghi ";
32 18
        for ($i=0; $i<strlen($string); $i++) {
33 15
            $pos=strpos($src, $string[$i]);
34 15
            if ($pos===false) {
35 3
                throw new \Exception("Please provide only numbers and alphanumerical characters");
36
            }
37 12
            $string[$i]=$dst[$pos];
38 8
        }
39 15
        return $string;
40
    }
41
42
    /**
43
     * Decodes a string by a simple shift of characters
44
     *
45
     * @param string $string
46
     * @return string
47
     * @throws \Exception
48
     */
49 18 View Code Duplication
    public function decodeString($string)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51 18
        $string=strtolower($string);
52 18
        $src="jklmnopqrstuvwxyz0123456789abcdefghi ";
53 18
        $dst="abcdefghijklmnopqrstuvwxyz0123456789 ";
54 18
        for ($i=0; $i<strlen($string); $i++) {
55 15
            $pos=strpos($src, $string[$i]);
56 15
            if ($pos===false) {
57 3
                throw new \Exception("Please provide only numbers and alphanumerical characters");
58
            }
59 12
            $string[$i]=$dst[$pos];
60 8
        }
61 15
        return $string;
62
    }
63
}
64