Completed
Push — master ( c81f6c...1650a0 )
by mw
07:33
created

src/Outline/ListTreeBuilder.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SRF\Outline;
4
5
use SMW\Query\PrintRequest;
6
use SRF\Outline\OutlineTree;
7
use SMWDataItem as DataItem;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since 3.1
12
 *
13
 * @author mwjames
14
 */
15
class ListTreeBuilder {
16
17
	/**
18
	 * @var []
19
	 */
20
	private $params = [];
21
22
	/**
23
	 * @var Linker
24
	 */
25
	private $linker;
26
27
	/**
28
	 * @param array $params
29
	 */
30 3
	public function __construct( array $params ) {
31 3
		$this->params = $params;
32 3
	}
33
34
	/**
35
	 * @since 3.1
36
	 *
37
	 * @param Linker|null|false $linker
38
	 */
39 1
	public function setLinker( $linker ) {
40 1
		$this->linker = $linker;
41 1
	}
42
43
	/**
44
	 * @since 3.1
45
	 *
46
	 * @param OutlineTree $tree
0 ignored issues
show
There is no parameter named $tree. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
	 *
48
	 * @return string
49
	 */
50 2
	public function build( OutlineTree $outlineTree ) {
51 2
		return $this->tree( $outlineTree );
52
	}
53
54 2
	private function tree( $outline_tree, $level = 0 ) {
55 2
		$text = "";
56
57 2
		if ( !is_null( $outline_tree->items ) ) {
58 2
			$text .= "<ul>\n";
59 2
			foreach ( $outline_tree->items as $item ) {
60 1
				$text .= "<li>{$this->item($item)}</li>\n";
61
			}
62 2
			$text .= "</ul>\n";
63
		}
64
65 2
		if ( $level > 0 ) {
66 1
			$text .= "<ul>\n";
67
		}
68
69 2
		$num_levels = count( $this->params['outlineproperties'] );
70
		// set font size and weight depending on level we're at
71 2
		$font_level = $level;
72
73 2
		if ( $num_levels < 4 ) {
74 2
			$font_level += ( 4 - $num_levels );
75
		}
76
77 2
		if ( $font_level == 0 ) {
78
			$font_size = 'x-large';
79 2
		} elseif ( $font_level == 1 ) {
80
			$font_size = 'large';
81 2
		} elseif ( $font_level == 2 ) {
82 1
			$font_size = 'medium';
83
		} else {
84 2
			$font_size = 'small';
85
		}
86
87 2
		if ( $font_level == 3 ) {
88 2
			$font_weight = 'bold';
89
		} else {
90 1
			$font_weight = 'regular';
91
		}
92
93 2
		foreach ( $outline_tree->tree as $key => $node ) {
94 1
			$text .= "<p style=\"font-size: $font_size; font-weight: $font_weight;\">$key</p>\n";
95 1
			$text .= $this->tree( $node, $level + 1 );
96
		}
97
98 2
		if ( $level > 0 ) {
99 1
			$text .= "</ul>\n";
100
		}
101
102 2
		return $text;
103
	}
104
105 1
	private function item( $item ) {
106 1
		$first_col = true;
107 1
		$found_values = false; // has anything but the first column been printed?
108 1
		$result = "";
109
110 1
		foreach ( $item->row as $resultArray ) {
111
112 1
			$printRequest = $resultArray->getPrintRequest();
113 1
			$val = $printRequest->getText( SMW_OUTPUT_WIKI, null );
114 1
			$first_value = true;
115
116 1
			if ( in_array( $val, $this->params['outlineproperties'] ) ) {
117 1
				continue;
118
			}
119
120 1
			$linker = $this->params['link'] === 'all' ? $this->linker : null;
121
122 1
			if ( $this->params['link'] === 'subject' && $printRequest->isMode( PrintRequest::PRINT_THIS ) ) {
123
				$linker = $this->linker;
124
			}
125
126 1
			while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) {
127
128 1
				if ( !$first_col && !$found_values ) { // first values after first column
129 1
					$result .= ' (';
130 1
					$found_values = true;
131 1
				} elseif ( $found_values || !$first_value ) {
132
					// any value after '(' or non-first values on first column
133
					$result .= ', ';
134
				}
135
136 1
				if ( $first_value ) { // first value in any column, print header
137 1
					$first_value = false;
138 1
					if ( $this->params['showHeaders'] && ( '' != $printRequest->getLabel() ) ) {
139 1
						$result .= $printRequest->getText( SMW_OUTPUT_WIKI, $linker ) . ' ';
140
					}
141
				}
142
143 1
				$dataItem = $dv->getDataItem();
144
145 1
				if ( $linker === null && $dataItem->getDIType() === DataItem::TYPE_WIKIPAGE && ( $caption = $dv->getDisplayTitle() ) !== '' ) {
146
					$dv->setCaption( $caption );
147
				}
148
149 1
				$result .= $dv->getShortText( SMW_OUTPUT_WIKI, $linker );
150
			}
151
152 1
			$first_col = false;
153
		}
154
155 1
		if ( $found_values ) {
156 1
			$result .= ')';
157
		}
158
159 1
		return $result;
160
	}
161
162
}