Departures::setFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * User: ms
4
 * Date: 29.08.15
5
 * Time: 11:00
6
 */
7
8
namespace Mvg\TextOutput;
9
10
/**
11
 * Class Departures
12
 * @package Mvg
13
 */
14
class Departures {
15
16
	/**
17
	 * @var \Mvg\Factories\Departures
18
	 */
19
	protected $departuresFactory = null;
20
21
	/**
22
	 * @var mixed
23
	 */
24
	protected $filter = null;
25
26
	/**
27
	 * @param \Mvg\Factories\Departures $departuresFactory
28
	 * @param mixed $filter
29
	 */
30
	public function __construct($departuresFactory, $filter = null) {
31
		$this->setDeparturesFactory($departuresFactory);
32
		$this->setFilter($filter);
33
	}
34
35
	/**
36
	 * @return mixed
37
	 */
38
	protected function getFilter() {
39
		return $this->filter;
40
	}
41
42
	/**
43
	 * @param mixed $filter
44
	 */
45
	protected function setFilter($filter) {
46
		$this->filter = $filter;
47
	}
48
49
50
	/**
51
	 * @return \Mvg\Factories\Departures
52
	 */
53
	protected function getDeparturesFactory() {
54
		return $this->departuresFactory;
55
	}
56
57
58
	/**
59
	 * @param \Mvg\Factories\Departures $departuresFactory
60
	 */
61
	protected function setDeparturesFactory($departuresFactory) {
62
		$this->departuresFactory = $departuresFactory;
63
	}
64
65
	/**
66
	 * found here http://stackoverflow.com/a/11871948
67
	 * @param $input
68
	 * @param $pad_length
69
	 * @param string $pad_string
70
	 * @param int $pad_type
71
	 * @return string
72
	 */
73
	public static function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) {
0 ignored issues
show
Coding Style introduced by
function mb_str_pad() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
$pad_length does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style Naming introduced by
The parameter $pad_length is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $pad_string is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $pad_type is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
74
		mb_internal_encoding('utf-8'); // @important
75
		$diff = strlen($input) - mb_strlen($input);
76
		return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
0 ignored issues
show
Coding Style introduced by
$pad_length does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
77
	}
78
79
	public function getOutput() {
80
		$maxLenLineNumber = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
81
		$maxLenDestination = 0;
82
		$maxLenTime = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
83
		$departuresItems = $this->getDeparturesFactory()->getItems($this->getFilter());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
84
		foreach ($departuresItems as $departureObject) {
85
86
			if (mb_strlen($departureObject->lineNumber) > $maxLenLineNumber) {
87
				$maxLenLineNumber = mb_strlen($departureObject->lineNumber);
88
			}
89
90
			if (mb_strlen($departureObject->destination) > $maxLenDestination) {
91
				$maxLenDestination = mb_strlen($departureObject->destination);
92
			}
93
			if (mb_strlen($departureObject->time) > $maxLenTime) {
94
				$maxLenTime = mb_strlen($departureObject->time);
95
			}
96
		}
97
		$str = sprintf('Abfahrtzeiten %s %s',
98
			$this->getDeparturesFactory()->getStation()
99
			, $this->getDeparturesFactory()->getCurrentTime()
100
		);
101
102
		$str .= "\n";
103
104
		foreach ($departuresItems as $departureObject) {
105
			$str .= self::mb_str_pad($departureObject->lineNumber, $maxLenLineNumber + 3, ' ', STR_PAD_RIGHT);
106
			$str .= self::mb_str_pad($departureObject->destination, $maxLenDestination + 3, ' ', STR_PAD_RIGHT);
107
			$str .= self::mb_str_pad($departureObject->time, $maxLenTime + 3, ' ', STR_PAD_RIGHT);
108
			$str .= "\n";
109
		}
110
		return $str;
111
	}
112
113
114
}