pdf_context::increase_length()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.2
cc 4
eloc 9
nc 2
nop 1
1
<?php
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
class pdf_context {
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...
21
22
	var $file;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
23
	var $buffer;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $buffer.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
24
	var $offset;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $offset.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
25
	var $length;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $length.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
26
27
	var $stack;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $stack.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
28
29
	// Constructor
30
31
	function pdf_context($f) {
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->file = $f;
33
		$this->reset();
34
	}
35
36
	// Optionally move the file
37
	// pointer to a new location
38
	// and reset the buffered data
39
40
	function reset($pos = null, $l = 100) {
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...
41
		if (!is_null ($pos)) {
42
			fseek ($this->file, $pos);
43
		}
44
45
		$this->buffer = $l > 0 ? fread($this->file, $l) : '';
46
		$this->length = strlen($this->buffer);
47
		if ($this->length < $l)
48
            $this->increase_length($l - $this->length);
49
		$this->offset = 0;
50
		$this->stack = array();
51
	}
52
53
	// Make sure that there is at least one
54
	// character beyond the current offset in
55
	// the buffer to prevent the tokenizer
56
	// from attempting to access data that does
57
	// not exist
58
59
	function ensure_content() {
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...
60
		if ($this->offset >= $this->length - 1) {
61
			return $this->increase_length();
62
		} else {
63
			return true;
64
		}
65
	}
66
67
	// Forcefully read more data into the buffer
68
69
	function increase_length($l=100) {
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...
70
		if (feof($this->file)) {
71
			return false;
72
		} else {
73
			$totalLength = $this->length + $l;
74
		    do {
75
                $this->buffer .= fread($this->file, $totalLength-$this->length);
76
            } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
77
			
78
			return true;
79
		}
80
	}
81
82
}