NewsTicker::parse()   C
last analyzed

Complexity

Conditions 10
Paths 63

Size

Total Lines 52
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 30
c 1
b 0
f 0
nc 63
nop 0
dl 0
loc 52
rs 6.2553

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * User: ms
4
 * Date: 14.09.15
5
 * Time: 21:24
6
 */
7
8
namespace  Mvg\Parser\Html;
9
use Mvg\Parser\AbstractParser;
10
/**
11
 * Class NewsTicker
12
 * @package Mvg\Parser\Html
13
 */
14
class NewsTicker extends AbstractParser {
15
16
	/**
17
	 * @var array
18
	 */
19
	protected $interferences = array();
20
21
	/**
22
	 * @param $response
23
	 */
24
	public function __construct($response) {
25
		parent::__construct($response);
26
		$this->parse();
27
28
	}
29
30
	protected function parse() {
31
		$jsonString = str_replace('//OK', '', $this->getHtmlResponse());
32
		$array = json_decode($jsonString);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
33
34
		$payload = null;
35
		//Find the interesting part
36
		foreach ($array as $item) {
37
			if (is_array($item)) {
38
				$payload = $item;
39
				break;
40
			}
41
		}
42
		if (null === $payload) {
43
			throw new \Exception('unable to parse payload from ' . $jsonString);
44
		}
45
46
		//Remove the Javastuff
47
		foreach ($payload as $key => $item) {
48
			if (preg_match('/de.swm.mvglive.gwt.client.newsticker.NewstickerItem/', $item)) {
49
				unset($payload[$key]);
50
			}
51
			if (preg_match('/java.util.ArrayList/', $item)) {
52
				unset($payload[$key]);
53
			}
54
		}
55
56
		if (0 != (count($payload) % 2)) {
57
			throw new \Exception('Item count is odd! ' . $jsonString);
58
59
		}
60
		$object = new \stdClass();
61
		foreach ($payload as $key => $item) {
62
			if (0 == ($key % 2)) {
63
				$object = new \stdClass();
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...
64
				$object->lines = $item;
65
66
				//get Lines with problems
67
				$stringToAnalyze = trim(str_replace('Linie(n)', '', $item));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
68
				$linesString = explode(':', $stringToAnalyze)[0];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
69
				$object->affectedLines = explode(',', $linesString);
70
				array_walk($object->affectedLines, function (&$item) {
71
					$item = trim($item);
72
				});
73
74
			} else {
75
				$object->messages = $item;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
76
				$this->interferences[] = $object;
77
			}
78
79
		}
80
81
	}
82
83
	public function getInterferences() {
84
		return $this->interferences;
85
	}
86
}