ASCII85Decode   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 0
loc 67
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ASCII85Decode() 0 3 1
C decode() 0 59 14
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
//
3
//  FPDI - Version 1.2.1
4
//
5
//    Copyright 2004-2008 Setasign - Jan Slabon
6
//
7
//  Licensed under the Apache License, Version 2.0 (the "License");
8
//  you may not use this file except in compliance with the License.
9
//  You may obtain a copy of the License at
10
//
11
//      http://www.apache.org/licenses/LICENSE-2.0
12
//
13
//  Unless required by applicable law or agreed to in writing, software
14
//  distributed under the License is distributed on an "AS IS" BASIS,
15
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
//  See the License for the specific language governing permissions and
17
//  limitations under the License.
18
//
19
20
if (!defined("ORD_z"))
21
	define("ORD_z",ord('z'));
22
if (!defined("ORD_exclmark"))
23
	define("ORD_exclmark", ord('!'));
24
if (!defined("ORD_u"))	
25
	define("ORD_u", ord("u"));
26
if (!defined("ORD_tilde"))
27
	define("ORD_tilde", ord('~'));
28
29
class ASCII85Decode {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
31
    function ASCII85Decode(&$fpdi) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
32
        $this->fpdi =& $fpdi;
0 ignored issues
show
Bug introduced by
The property fpdi does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
    }
34
35
36
    function decode($in) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
        $out = "";
38
        $state = 0;
39
        $chn = null;
40
        
41
        $l = strlen($in);
42
        
43
        for ($k = 0; $k < $l; ++$k) {
44
            $ch = ord($in[$k]) & 0xff;
45
            
46
            if ($ch == ORD_tilde) {
47
                break;
48
            }
49
            if (preg_match("/^\s$/",chr($ch))) {
50
                continue;
51
            }
52
            if ($ch == ORD_z && $state == 0) {
53
                $out .= chr(0).chr(0).chr(0).chr(0);
54
                continue;
55
            }
56
            if ($ch < ORD_exclmark || $ch > ORD_u) {
57
                $this->fpdi->error("Illegal character in ASCII85Decode.");
58
            }
59
            
60
            $chn[$state++] = $ch - ORD_exclmark;
61
            
62
            if ($state == 5) {
63
                $state = 0;
64
                $r = 0;
65
                for ($j = 0; $j < 5; ++$j)
66
                    $r = $r * 85 + $chn[$j];
67
                $out .= chr($r >> 24);
68
                $out .= chr($r >> 16);
69
                $out .= chr($r >> 8);
70
                $out .= chr($r);
71
            }
72
        }
73
        $r = 0;
0 ignored issues
show
Unused Code introduced by
$r is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
        
75
        if ($state == 1)
76
            $this->fpdi->error("Illegal length in ASCII85Decode.");
77
        if ($state == 2) {
78
            $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
79
            $out .= chr($r >> 24);
80
        }
81
        else if ($state == 3) {
82
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + ($chn[2]+1) * 85 * 85;
83
            $out .= chr($r >> 24);
84
            $out .= chr($r >> 16);
85
        }
86
        else if ($state == 4) {
87
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + $chn[2] * 85 * 85  + ($chn[3]+1) * 85 ;
88
            $out .= chr($r >> 24);
89
            $out .= chr($r >> 16);
90
            $out .= chr($r >> 8);
91
        }
92
93
        return $out;
94
    }
95
}