Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
74.07% |
20 / 27 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Polygon | |
74.07% |
20 / 27 |
|
25.00% |
1 / 4 |
15.95 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getElementName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setProperty | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
9.01 | |||
| getPropertyValidValues | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | namespace MultiMaps; |
| 3 | |
| 4 | /** |
| 5 | * Polygon class for collection of map elements |
| 6 | * |
| 7 | * @file Polygon.php |
| 8 | * @ingroup MultiMaps |
| 9 | * @author Pavel Astakhov <pastakhov@yandex.ru> |
| 10 | * @license GPL-2.0-or-later |
| 11 | * @property boolean $fill |
| 12 | * @property string $fillcolor |
| 13 | * @property string $fillopacity |
| 14 | */ |
| 15 | class Polygon extends Line { |
| 16 | |
| 17 | /** |
| 18 | * @var array Values for set fill to true |
| 19 | */ |
| 20 | protected static $fill_true = [ 'yes', '1', 'true' ]; |
| 21 | |
| 22 | /** |
| 23 | * @var array Values for set fill to false |
| 24 | */ |
| 25 | protected static $fill_false = [ 'no', '0', 'false' ]; |
| 26 | |
| 27 | /** |
| 28 | * Constructor |
| 29 | */ |
| 30 | function __construct() { |
| 31 | parent::__construct(); |
| 32 | |
| 33 | $this->availableProperties = array_merge( |
| 34 | $this->availableProperties, |
| 35 | [ 'fillcolor', 'fillopacity', 'fill' ] |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns element name |
| 41 | * return string Element name |
| 42 | */ |
| 43 | public function getElementName() { |
| 44 | return 'Polygon'; // TODO i18n? |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Set element property by name |
| 49 | * @param string $name |
| 50 | * @param mixed $value |
| 51 | * @return bool |
| 52 | */ |
| 53 | public function setProperty( $name, $value ) { |
| 54 | $name = strtolower( $name ); |
| 55 | $value = trim( $value ); |
| 56 | |
| 57 | switch ( $name ) { |
| 58 | case 'fill': |
| 59 | if ( $value === true || array_search( $value, self::$fill_true ) !== false ) { |
| 60 | $this->properties['fill'] = true; |
| 61 | return true; |
| 62 | } elseif ( $value == false || array_search( $value, self::$fill_false ) !== false ) { |
| 63 | $this->properties['fill'] = false; |
| 64 | $this->unsetProperty( 'fillcolor' ); |
| 65 | $this->unsetProperty( 'fillopacity' ); |
| 66 | return true; |
| 67 | } else { |
| 68 | $this->errormessages[] = \wfMessage( 'multimaps-element-illegal-value', $name, $value, '"' . implode( '", "', self::getPropertyValidValues( $name ) ) . '"' )->escaped(); |
| 69 | return false; |
| 70 | } |
| 71 | break; |
| 72 | case 'fillcolor': |
| 73 | case 'fillopacity': |
| 74 | $this->fill = true; |
| 75 | return parent::setProperty( $name, $value ); |
| 76 | default: |
| 77 | return parent::setProperty( $name, $value ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns array of valid values for property |
| 83 | * This function helps test code |
| 84 | * @param string $name |
| 85 | * @return array |
| 86 | */ |
| 87 | public static function getPropertyValidValues( $name ) { |
| 88 | $name = strtolower( $name ); |
| 89 | |
| 90 | switch ( $name ) { |
| 91 | case 'fill': |
| 92 | return array_merge( self::$fill_true, self::$fill_false ); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | } |