@@ -59,8 +59,7 @@ discard block |
||
| 59 | 59 | try |
| 60 | 60 | { |
| 61 | 61 | throw new BaseException(''); |
| 62 | - } |
|
| 63 | - catch(BaseException $e) |
|
| 62 | + } catch(BaseException $e) |
|
| 64 | 63 | { |
| 65 | 64 | echo self::createInfo($e)->toString(); |
| 66 | 65 | } |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | try |
| 75 | 74 | { |
| 76 | 75 | throw new BaseException(''); |
| 77 | - } |
|
| 78 | - catch(BaseException $e) |
|
| 76 | + } catch(BaseException $e) |
|
| 79 | 77 | { |
| 80 | 78 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 81 | 79 | echo self::createInfo($e)->toString(); |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class BaseException extends \Exception |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | protected $details; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @param string $details |
|
| 33 | - * @param int $code |
|
| 34 | - * @param \Exception $previous |
|
| 35 | - */ |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @param string $details |
|
| 33 | + * @param int $code |
|
| 34 | + * @param \Exception $previous |
|
| 35 | + */ |
|
| 36 | 36 | public function __construct(string $message, $details=null, $code=null, $previous=null) |
| 37 | 37 | { |
| 38 | 38 | parent::__construct($message, $code, $previous); |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | $this->details = $details; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Retrieves the detailed error description, if any. |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 43 | + /** |
|
| 44 | + * Retrieves the detailed error description, if any. |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | 47 | public function getDetails() : string |
| 48 | 48 | { |
| 49 | 49 | if($this->details !== null) { |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | return ''; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Displays pertinent information on the exception. |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * Displays pertinent information on the exception. |
|
| 58 | + */ |
|
| 59 | 59 | public function display() : void |
| 60 | 60 | { |
| 61 | 61 | if(!headers_sent()) { |
@@ -65,20 +65,20 @@ discard block |
||
| 65 | 65 | echo $this->getInfo(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Retrieves information on the exception that can be |
|
| 70 | - * easily accessed. |
|
| 71 | - * |
|
| 72 | - * @return ConvertHelper_ThrowableInfo |
|
| 73 | - */ |
|
| 68 | + /** |
|
| 69 | + * Retrieves information on the exception that can be |
|
| 70 | + * easily accessed. |
|
| 71 | + * |
|
| 72 | + * @return ConvertHelper_ThrowableInfo |
|
| 73 | + */ |
|
| 74 | 74 | public function getInfo() : ConvertHelper_ThrowableInfo |
| 75 | 75 | { |
| 76 | 76 | return ConvertHelper::throwable2info($this); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Dumps a current PHP function trace, as a text only string. |
|
| 81 | - */ |
|
| 79 | + /** |
|
| 80 | + * Dumps a current PHP function trace, as a text only string. |
|
| 81 | + */ |
|
| 82 | 82 | public static function dumpTraceAsString() : void |
| 83 | 83 | { |
| 84 | 84 | try |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Dumps a current PHP function trace, with HTML styling. |
|
| 96 | - */ |
|
| 94 | + /** |
|
| 95 | + * Dumps a current PHP function trace, with HTML styling. |
|
| 96 | + */ |
|
| 97 | 97 | public static function dumpTraceAsHTML() : void |
| 98 | 98 | { |
| 99 | 99 | try |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Creates an exception info instance from a throwable instance. |
|
| 113 | - * |
|
| 114 | - * @param Throwable $e |
|
| 115 | - * @return ConvertHelper_ThrowableInfo |
|
| 116 | - * @see ConvertHelper::throwable2info() |
|
| 117 | - */ |
|
| 111 | + /** |
|
| 112 | + * Creates an exception info instance from a throwable instance. |
|
| 113 | + * |
|
| 114 | + * @param Throwable $e |
|
| 115 | + * @return ConvertHelper_ThrowableInfo |
|
| 116 | + * @see ConvertHelper::throwable2info() |
|
| 117 | + */ |
|
| 118 | 118 | public static function createInfo(Throwable $e) : ConvertHelper_ThrowableInfo |
| 119 | 119 | { |
| 120 | 120 | return ConvertHelper::throwable2info($e); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param int $code |
| 34 | 34 | * @param \Exception $previous |
| 35 | 35 | */ |
| 36 | - public function __construct(string $message, $details=null, $code=null, $previous=null) |
|
| 36 | + public function __construct(string $message, $details = null, $code = null, $previous = null) |
|
| 37 | 37 | { |
| 38 | 38 | parent::__construct($message, $code, $previous); |
| 39 | 39 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function getDetails() : string |
| 48 | 48 | { |
| 49 | - if($this->details !== null) { |
|
| 49 | + if ($this->details !== null) { |
|
| 50 | 50 | return $this->details; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function display() : void |
| 60 | 60 | { |
| 61 | - if(!headers_sent()) { |
|
| 61 | + if (!headers_sent()) { |
|
| 62 | 62 | header('Content-type:text/plain; charset=utf-8'); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | throw new BaseException(''); |
| 87 | 87 | } |
| 88 | - catch(BaseException $e) |
|
| 88 | + catch (BaseException $e) |
|
| 89 | 89 | { |
| 90 | 90 | echo self::createInfo($e)->toString(); |
| 91 | 91 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | throw new BaseException(''); |
| 102 | 102 | } |
| 103 | - catch(BaseException $e) |
|
| 103 | + catch (BaseException $e) |
|
| 104 | 104 | { |
| 105 | 105 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 106 | 106 | echo self::createInfo($e)->toString(); |
@@ -38,38 +38,38 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | protected $text; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | 44 | protected $trimmed; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var int |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var int |
|
| 48 | + */ |
|
| 49 | 49 | protected $lineNumber; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | 54 | protected $type; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | 59 | protected $varName = ''; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | 64 | protected $varValue = ''; |
| 65 | 65 | |
| 66 | 66 | protected $valueUnquoted = ''; |
| 67 | 67 | |
| 68 | 68 | protected $quoteStyle = ''; |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 70 | + /** |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | 73 | protected $sectionName = ''; |
| 74 | 74 | |
| 75 | 75 | public function __construct(string $text, int $lineNumber) |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $this->trimmed = trim($text); |
| 79 | 79 | $this->lineNumber = $lineNumber; |
| 80 | 80 | |
| 81 | - if(empty($this->trimmed)) |
|
| 81 | + if (empty($this->trimmed)) |
|
| 82 | 82 | { |
| 83 | 83 | $this->type = self::TYPE_EMPTY; |
| 84 | 84 | return; |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $startChar = substr($this->trimmed, 0, 1); |
| 88 | 88 | |
| 89 | - if($startChar === ';') |
|
| 89 | + if ($startChar === ';') |
|
| 90 | 90 | { |
| 91 | 91 | $this->type = self::TYPE_COMMENT; |
| 92 | 92 | } |
| 93 | - else if($startChar === '[') |
|
| 93 | + else if ($startChar === '[') |
|
| 94 | 94 | { |
| 95 | 95 | $this->type = self::TYPE_SECTION_DECLARATION; |
| 96 | 96 | $this->sectionName = trim($this->trimmed, '[]'); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | else |
| 100 | 100 | { |
| 101 | 101 | $pos = strpos($this->trimmed, '='); |
| 102 | - if($pos === false) |
|
| 102 | + if ($pos === false) |
|
| 103 | 103 | { |
| 104 | 104 | $this->type = self::TYPE_INVALID; |
| 105 | 105 | return; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->type = self::TYPE_VALUE; |
| 109 | 109 | $this->varName = trim(substr($this->trimmed, 0, $pos)); |
| 110 | 110 | |
| 111 | - $this->parseValue(substr($this->trimmed, $pos+1)); |
|
| 111 | + $this->parseValue(substr($this->trimmed, $pos + 1)); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $value = $this->varValue; |
| 120 | 120 | |
| 121 | - if(substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
| 121 | + if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
| 122 | 122 | { |
| 123 | 123 | $value = trim($value, '"'); |
| 124 | 124 | $this->quoteStyle = '"'; |
| 125 | 125 | } |
| 126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 126 | + else if (substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 127 | 127 | { |
| 128 | 128 | $value = trim($value, "'"); |
| 129 | 129 | $this->quoteStyle = "'"; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public function getQuotedVarValue() : string |
| 146 | 146 | { |
| 147 | - if($this->quoteStyle === '') { |
|
| 147 | + if ($this->quoteStyle === '') { |
|
| 148 | 148 | return $this->getVarValue(); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | public function setValue($value) : IniHelper_Line |
| 200 | 200 | { |
| 201 | - if(!is_scalar($value)) |
|
| 201 | + if (!is_scalar($value)) |
|
| 202 | 202 | { |
| 203 | 203 | throw new IniHelper_Exception( |
| 204 | 204 | 'Cannot use non-scalar values.', |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | public function toString() : string |
| 220 | 220 | { |
| 221 | - switch($this->type) |
|
| 221 | + switch ($this->type) |
|
| 222 | 222 | { |
| 223 | 223 | case self::TYPE_EMPTY: |
| 224 | 224 | case self::TYPE_INVALID: |
@@ -89,14 +89,12 @@ discard block |
||
| 89 | 89 | if($startChar === ';') |
| 90 | 90 | { |
| 91 | 91 | $this->type = self::TYPE_COMMENT; |
| 92 | - } |
|
| 93 | - else if($startChar === '[') |
|
| 92 | + } else if($startChar === '[') |
|
| 94 | 93 | { |
| 95 | 94 | $this->type = self::TYPE_SECTION_DECLARATION; |
| 96 | 95 | $this->sectionName = trim($this->trimmed, '[]'); |
| 97 | 96 | $this->sectionName = trim($this->sectionName); // remove any whitespace |
| 98 | - } |
|
| 99 | - else |
|
| 97 | + } else |
|
| 100 | 98 | { |
| 101 | 99 | $pos = strpos($this->trimmed, '='); |
| 102 | 100 | if($pos === false) |
@@ -122,8 +120,7 @@ discard block |
||
| 122 | 120 | { |
| 123 | 121 | $value = trim($value, '"'); |
| 124 | 122 | $this->quoteStyle = '"'; |
| 125 | - } |
|
| 126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 123 | + } else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 127 | 124 | { |
| 128 | 125 | $value = trim($value, "'"); |
| 129 | 126 | $this->quoteStyle = "'"; |
@@ -21,19 +21,19 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class IniHelper_Section |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var IniHelper |
|
| 26 | - */ |
|
| 24 | + /** |
|
| 25 | + * @var IniHelper |
|
| 26 | + */ |
|
| 27 | 27 | protected $ini; |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | 32 | protected $name; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var IniHelper_Line[] |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var IniHelper_Line[] |
|
| 36 | + */ |
|
| 37 | 37 | protected $lines = array(); |
| 38 | 38 | |
| 39 | 39 | public function __construct(IniHelper $ini, string $name) |
@@ -42,33 +42,33 @@ discard block |
||
| 42 | 42 | $this->name = $name; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The section's name. |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 45 | + /** |
|
| 46 | + * The section's name. |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | 49 | public function getName() : string |
| 50 | 50 | { |
| 51 | 51 | return $this->name; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Whether this is the default section: this |
|
| 56 | - * is used internally to store all variables that |
|
| 57 | - * are not in any specific section. |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 54 | + /** |
|
| 55 | + * Whether this is the default section: this |
|
| 56 | + * is used internally to store all variables that |
|
| 57 | + * are not in any specific section. |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | 61 | public function isDefault() : bool |
| 62 | 62 | { |
| 63 | 63 | return $this->name === IniHelper::SECTION_DEFAULT; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Adds a line instance to the section. |
|
| 68 | - * |
|
| 69 | - * @param IniHelper_Line $line |
|
| 70 | - * @return IniHelper_Section |
|
| 71 | - */ |
|
| 66 | + /** |
|
| 67 | + * Adds a line instance to the section. |
|
| 68 | + * |
|
| 69 | + * @param IniHelper_Line $line |
|
| 70 | + * @return IniHelper_Section |
|
| 71 | + */ |
|
| 72 | 72 | public function addLine(IniHelper_Line $line) : IniHelper_Section |
| 73 | 73 | { |
| 74 | 74 | $this->lines[] = $line; |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Converts the values contained in the section into |
|
| 81 | - * an associative array. |
|
| 82 | - * |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 79 | + /** |
|
| 80 | + * Converts the values contained in the section into |
|
| 81 | + * an associative array. |
|
| 82 | + * |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | 85 | public function toArray() : array |
| 86 | 86 | { |
| 87 | 87 | $result = array(); |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | return $result; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Converts the section's lines into an INI string. |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 117 | + /** |
|
| 118 | + * Converts the section's lines into an INI string. |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | 122 | public function toString() |
| 123 | 123 | { |
| 124 | 124 | $lines = array(); |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | return implode($this->ini->getEOLChar(), $lines); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Deletes a line from the section. |
|
| 145 | - * |
|
| 146 | - * @param IniHelper_Line $toDelete |
|
| 147 | - * @return IniHelper_Section |
|
| 148 | - */ |
|
| 143 | + /** |
|
| 144 | + * Deletes a line from the section. |
|
| 145 | + * |
|
| 146 | + * @param IniHelper_Line $toDelete |
|
| 147 | + * @return IniHelper_Section |
|
| 148 | + */ |
|
| 149 | 149 | public function deleteLine(IniHelper_Line $toDelete) : IniHelper_Section |
| 150 | 150 | { |
| 151 | 151 | $keep = array(); |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | return $this; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Sets the value of a variable, overwriting any existing value. |
|
| 167 | - * |
|
| 168 | - * @param string $name |
|
| 169 | - * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
| 170 | - * @return IniHelper_Section |
|
| 171 | - */ |
|
| 165 | + /** |
|
| 166 | + * Sets the value of a variable, overwriting any existing value. |
|
| 167 | + * |
|
| 168 | + * @param string $name |
|
| 169 | + * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
| 170 | + * @return IniHelper_Section |
|
| 171 | + */ |
|
| 172 | 172 | public function setValue(string $name, $value) : IniHelper_Section |
| 173 | 173 | { |
| 174 | 174 | $lines = $this->getLinesByVariable($name); |
@@ -229,15 +229,15 @@ discard block |
||
| 229 | 229 | return $this; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Adds a variable value to the section. Unlike setValue(), this |
|
| 234 | - * will not overwrite any existing value. If the name is an existing |
|
| 235 | - * variable name, it will be converted to duplicate keys. |
|
| 236 | - * |
|
| 237 | - * @param string $name |
|
| 238 | - * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 239 | - * @return IniHelper_Section |
|
| 240 | - */ |
|
| 232 | + /** |
|
| 233 | + * Adds a variable value to the section. Unlike setValue(), this |
|
| 234 | + * will not overwrite any existing value. If the name is an existing |
|
| 235 | + * variable name, it will be converted to duplicate keys. |
|
| 236 | + * |
|
| 237 | + * @param string $name |
|
| 238 | + * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 239 | + * @return IniHelper_Section |
|
| 240 | + */ |
|
| 241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
| 242 | 242 | { |
| 243 | 243 | // array value? Treat it as duplicate keys. |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Retrieves all lines for the specified variable name. |
|
| 300 | - * |
|
| 301 | - * @param string $name |
|
| 302 | - * @return \AppUtils\IniHelper_Line[] |
|
| 303 | - */ |
|
| 298 | + /** |
|
| 299 | + * Retrieves all lines for the specified variable name. |
|
| 300 | + * |
|
| 301 | + * @param string $name |
|
| 302 | + * @return \AppUtils\IniHelper_Line[] |
|
| 303 | + */ |
|
| 304 | 304 | public function getLinesByVariable(string $name) |
| 305 | 305 | { |
| 306 | 306 | $result = array(); |
@@ -86,15 +86,15 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $result = array(); |
| 88 | 88 | |
| 89 | - foreach($this->lines as $line) |
|
| 89 | + foreach ($this->lines as $line) |
|
| 90 | 90 | { |
| 91 | - if(!$line->isValue()) { |
|
| 91 | + if (!$line->isValue()) { |
|
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $name = $line->getVarName(); |
| 96 | 96 | |
| 97 | - if(!isset($result[$name])) |
|
| 97 | + if (!isset($result[$name])) |
|
| 98 | 98 | { |
| 99 | 99 | $result[$name] = $line->getVarValue(); |
| 100 | 100 | continue; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | // name exists in collection? Then this is a |
| 104 | 104 | // duplicate key and we need to convert it to |
| 105 | 105 | // an indexed array of values. |
| 106 | - if(!is_array($result[$name])) |
|
| 106 | + if (!is_array($result[$name])) |
|
| 107 | 107 | { |
| 108 | 108 | $result[$name] = array($result[$name]); |
| 109 | 109 | } |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | public function toString() |
| 123 | 123 | { |
| 124 | 124 | $lines = array(); |
| 125 | - if(!$this->isDefault()) |
|
| 125 | + if (!$this->isDefault()) |
|
| 126 | 126 | { |
| 127 | 127 | $lines[] = '['.$this->getName().']'; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - foreach($this->lines as $line) |
|
| 130 | + foreach ($this->lines as $line) |
|
| 131 | 131 | { |
| 132 | 132 | // we already did this |
| 133 | - if($line->isSection()) { |
|
| 133 | + if ($line->isSection()) { |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $keep = array(); |
| 152 | 152 | |
| 153 | - foreach($this->lines as $line) |
|
| 153 | + foreach ($this->lines as $line) |
|
| 154 | 154 | { |
| 155 | - if($line !== $toDelete) { |
|
| 155 | + if ($line !== $toDelete) { |
|
| 156 | 156 | $keep[] = $line; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -177,23 +177,23 @@ discard block |
||
| 177 | 177 | // Removes any superfluous values that may |
| 178 | 178 | // already exist, if there are more than the |
| 179 | 179 | // new set of values. |
| 180 | - if(is_array($value)) |
|
| 180 | + if (is_array($value)) |
|
| 181 | 181 | { |
| 182 | 182 | $values = array_values($value); |
| 183 | 183 | $amountNew = count($values); |
| 184 | 184 | $amountExisting = count($lines); |
| 185 | 185 | |
| 186 | 186 | $max = $amountNew; |
| 187 | - if($amountExisting > $max) { |
|
| 187 | + if ($amountExisting > $max) { |
|
| 188 | 188 | $max = $amountExisting; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - for($i=0; $i < $max; $i++) |
|
| 191 | + for ($i = 0; $i < $max; $i++) |
|
| 192 | 192 | { |
| 193 | 193 | // new value exists |
| 194 | - if(isset($values[$i])) |
|
| 194 | + if (isset($values[$i])) |
|
| 195 | 195 | { |
| 196 | - if(isset($lines[$i])) { |
|
| 196 | + if (isset($lines[$i])) { |
|
| 197 | 197 | $lines[$i]->setValue($values[$i]); |
| 198 | 198 | } else { |
| 199 | 199 | $this->addValueLine($name, $values[$i]); |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | else |
| 212 | 212 | { |
| 213 | 213 | // remove all superfluous lines |
| 214 | - if(!empty($lines)) |
|
| 214 | + if (!empty($lines)) |
|
| 215 | 215 | { |
| 216 | 216 | $line = array_shift($lines); // keep only the first line |
| 217 | 217 | $line->setValue($value); |
| 218 | 218 | |
| 219 | - foreach($lines as $delete) { |
|
| 219 | + foreach ($lines as $delete) { |
|
| 220 | 220 | $this->deleteLine($delete); |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
| 242 | 242 | { |
| 243 | 243 | // array value? Treat it as duplicate keys. |
| 244 | - if(is_array($value)) |
|
| 244 | + if (is_array($value)) |
|
| 245 | 245 | { |
| 246 | 246 | $values = array_values($value); |
| 247 | 247 | |
| 248 | - foreach($values as $setValue) |
|
| 248 | + foreach ($values as $setValue) |
|
| 249 | 249 | { |
| 250 | 250 | $this->addValue($name, $setValue); |
| 251 | 251 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $lines = $this->getLinesByVariable($name); |
| 257 | 257 | |
| 258 | - if(empty($lines)) |
|
| 258 | + if (empty($lines)) |
|
| 259 | 259 | { |
| 260 | 260 | $this->addValueLine($name, $value); |
| 261 | 261 | } |
@@ -263,15 +263,15 @@ discard block |
||
| 263 | 263 | { |
| 264 | 264 | $found = false; |
| 265 | 265 | |
| 266 | - foreach($lines as $line) |
|
| 266 | + foreach ($lines as $line) |
|
| 267 | 267 | { |
| 268 | - if($line->getVarValue() === $value) { |
|
| 268 | + if ($line->getVarValue() === $value) { |
|
| 269 | 269 | $found = $line; |
| 270 | 270 | break; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if(!$found) |
|
| 274 | + if (!$found) |
|
| 275 | 275 | { |
| 276 | 276 | $this->addValueLine($name, $value); |
| 277 | 277 | } |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | { |
| 306 | 306 | $result = array(); |
| 307 | 307 | |
| 308 | - foreach($this->lines as $line) |
|
| 308 | + foreach ($this->lines as $line) |
|
| 309 | 309 | { |
| 310 | - if($line->isValue() && $line->getVarName() === $name) { |
|
| 310 | + if ($line->isValue() && $line->getVarName() === $name) { |
|
| 311 | 311 | $result[] = $line; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -198,8 +198,7 @@ discard block |
||
| 198 | 198 | } else { |
| 199 | 199 | $this->addValueLine($name, $values[$i]); |
| 200 | 200 | } |
| 201 | - } |
|
| 202 | - else |
|
| 201 | + } else |
|
| 203 | 202 | { |
| 204 | 203 | $this->deleteLine($lines[$i]); |
| 205 | 204 | } |
@@ -219,8 +218,7 @@ discard block |
||
| 219 | 218 | foreach($lines as $delete) { |
| 220 | 219 | $this->deleteLine($delete); |
| 221 | 220 | } |
| 222 | - } |
|
| 223 | - else |
|
| 221 | + } else |
|
| 224 | 222 | { |
| 225 | 223 | $this->addValueLine($name, $value); |
| 226 | 224 | } |
@@ -258,8 +256,7 @@ discard block |
||
| 258 | 256 | if(empty($lines)) |
| 259 | 257 | { |
| 260 | 258 | $this->addValueLine($name, $value); |
| 261 | - } |
|
| 262 | - else |
|
| 259 | + } else |
|
| 263 | 260 | { |
| 264 | 261 | $found = false; |
| 265 | 262 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | return $this->setOption('separatorChar', $char); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function setTrailingNewline($useNewline=true) |
|
| 20 | + public function setTrailingNewline($useNewline = true) |
|
| 21 | 21 | { |
| 22 | 22 | return $this->setOption('trailingNewline', $useNewline); |
| 23 | 23 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $args = $args[0]; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $this->lines[] = '"' . implode('"'.$this->getOption('separatorChar').'"', $args) . '"'; |
|
| 41 | + $this->lines[] = '"'.implode('"'.$this->getOption('separatorChar').'"', $args).'"'; |
|
| 42 | 42 | |
| 43 | 43 | return $this; |
| 44 | 44 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $csv = implode(PHP_EOL, $this->lines); |
| 56 | 56 | |
| 57 | - if($this->getOption('trailingNewline')) { |
|
| 57 | + if ($this->getOption('trailingNewline')) { |
|
| 58 | 58 | $csv .= PHP_EOL; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | public function setOption($name, $value) |
| 67 | 67 | { |
| 68 | - if(!isset($this->options)) { |
|
| 68 | + if (!isset($this->options)) { |
|
| 69 | 69 | $this->options = $this->getDefaultOptions(); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function setOptions($options) |
| 77 | 77 | { |
| 78 | - foreach($options as $name => $value) { |
|
| 78 | + foreach ($options as $name => $value) { |
|
| 79 | 79 | $this->setOption($name, $value); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return $this; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function getOption($name, $default=null) |
|
| 85 | + public function getOption($name, $default = null) |
|
| 86 | 86 | { |
| 87 | - if(!isset($this->options)) { |
|
| 87 | + if (!isset($this->options)) { |
|
| 88 | 88 | $this->options = $this->getDefaultOptions(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if(isset($this->options[$name])) { |
|
| 91 | + if (isset($this->options[$name])) { |
|
| 92 | 92 | return $this->options[$name]; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | public function hasOption($name) |
| 99 | 99 | { |
| 100 | - if(!isset($this->options)) { |
|
| 100 | + if (!isset($this->options)) { |
|
| 101 | 101 | $this->options = $this->getDefaultOptions(); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | public function getOptions() |
| 108 | 108 | { |
| 109 | - if(!isset($this->options)) { |
|
| 109 | + if (!isset($this->options)) { |
|
| 110 | 110 | $this->options = $this->getDefaultOptions(); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | public function isOption($name, $value) |
| 117 | 117 | { |
| 118 | - if($this->getOption($name) === $value) { |
|
| 118 | + if ($this->getOption($name) === $value) { |
|
| 119 | 119 | return true; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $this->path = realpath($path); |
| 53 | 53 | |
| 54 | - if($this->path === false) |
|
| 54 | + if ($this->path === false) |
|
| 55 | 55 | { |
| 56 | 56 | throw new FileHelper_Exception( |
| 57 | 57 | 'Cannot extract file information: file not found.', |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | $code = file_get_contents($this->path); |
| 132 | 132 | |
| 133 | - if($code === false) |
|
| 133 | + if ($code === false) |
|
| 134 | 134 | { |
| 135 | 135 | throw new FileHelper_Exception( |
| 136 | 136 | 'Cannot open file for parsing.', |
@@ -149,24 +149,24 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | $result = array(); |
| 151 | 151 | preg_match_all('/namespace[\s]+([^;]+);/six', $code, $result, PREG_PATTERN_ORDER); |
| 152 | - if(isset($result[0]) && isset($result[0][0])) { |
|
| 152 | + if (isset($result[0]) && isset($result[0][0])) { |
|
| 153 | 153 | $this->namespace = trim($result[1][0]); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $result = array(); |
| 157 | 157 | preg_match_all('/(abstract|final)[\s]+class[\s]+([\sa-z0-9\\\\_,]+){|class[\s]+([\sa-z0-9\\\\_,]+){/six', $code, $result, PREG_PATTERN_ORDER); |
| 158 | 158 | |
| 159 | - if(!isset($result[0]) || !isset($result[0][0])) { |
|
| 159 | + if (!isset($result[0]) || !isset($result[0][0])) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $indexes = array_keys($result[0]); |
| 164 | 164 | |
| 165 | - foreach($indexes as $idx) |
|
| 165 | + foreach ($indexes as $idx) |
|
| 166 | 166 | { |
| 167 | 167 | $keyword = $result[1][$idx]; |
| 168 | 168 | $declaration = $result[2][$idx]; |
| 169 | - if(empty($keyword)) { |
|
| 169 | + if (empty($keyword)) { |
|
| 170 | 170 | $declaration = $result[3][$idx]; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -40,17 +40,17 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | protected $classes = array(); |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The namespace detected in the file, if any. |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 43 | + /** |
|
| 44 | + * The namespace detected in the file, if any. |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | 47 | protected $namespace = ''; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $path The path to the PHP file to parse. |
|
| 51 | - * @throws FileHelper_Exception |
|
| 52 | - * @see FileHelper::findPHPClasses() |
|
| 53 | - */ |
|
| 49 | + /** |
|
| 50 | + * @param string $path The path to the PHP file to parse. |
|
| 51 | + * @throws FileHelper_Exception |
|
| 52 | + * @see FileHelper::findPHPClasses() |
|
| 53 | + */ |
|
| 54 | 54 | public function __construct(string $path) |
| 55 | 55 | { |
| 56 | 56 | $this->path = realpath($path); |
@@ -70,66 +70,66 @@ discard block |
||
| 70 | 70 | $this->parseFile(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * The name of the namespace of the classes in the file, if any. |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 73 | + /** |
|
| 74 | + * The name of the namespace of the classes in the file, if any. |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | 77 | public function getNamespace() : string |
| 78 | 78 | { |
| 79 | 79 | return $this->namespace; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Whether the file contains a namespace. |
|
| 84 | - * @return bool |
|
| 85 | - */ |
|
| 82 | + /** |
|
| 83 | + * Whether the file contains a namespace. |
|
| 84 | + * @return bool |
|
| 85 | + */ |
|
| 86 | 86 | public function hasNamespace() : bool |
| 87 | 87 | { |
| 88 | 88 | return !empty($this->namespace); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * The absolute path to the file. |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 91 | + /** |
|
| 92 | + * The absolute path to the file. |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | 95 | public function getPath() : string |
| 96 | 96 | { |
| 97 | 97 | return $this->path; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Whether any classes were found in the file. |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 100 | + /** |
|
| 101 | + * Whether any classes were found in the file. |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | 104 | public function hasClasses() : bool |
| 105 | 105 | { |
| 106 | 106 | return !empty($this->classes); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * The names of the classes that were found in the file (with namespace if any). |
|
| 111 | - * @return string[] |
|
| 112 | - */ |
|
| 109 | + /** |
|
| 110 | + * The names of the classes that were found in the file (with namespace if any). |
|
| 111 | + * @return string[] |
|
| 112 | + */ |
|
| 113 | 113 | public function getClassNames() : array |
| 114 | 114 | { |
| 115 | 115 | return array_keys($this->classes); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Retrieves all classes that were detected in the file, |
|
| 120 | - * which can be used to retrieve more information about |
|
| 121 | - * them. |
|
| 122 | - * |
|
| 123 | - * @return FileHelper_PHPClassInfo_Class[] |
|
| 124 | - */ |
|
| 118 | + /** |
|
| 119 | + * Retrieves all classes that were detected in the file, |
|
| 120 | + * which can be used to retrieve more information about |
|
| 121 | + * them. |
|
| 122 | + * |
|
| 123 | + * @return FileHelper_PHPClassInfo_Class[] |
|
| 124 | + */ |
|
| 125 | 125 | public function getClasses() : array |
| 126 | 126 | { |
| 127 | 127 | return array_values($this->classes); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @throws FileHelper_Exception |
|
| 132 | - */ |
|
| 130 | + /** |
|
| 131 | + * @throws FileHelper_Exception |
|
| 132 | + */ |
|
| 133 | 133 | protected function parseFile() : void |
| 134 | 134 | { |
| 135 | 135 | $code = file_get_contents($this->path); |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Strips all whitespace from the string, replacing it with |
|
| 189 | - * regular spaces (newlines, tabs, etc.). |
|
| 190 | - * |
|
| 191 | - * @param string $string |
|
| 192 | - * @return string |
|
| 193 | - */ |
|
| 187 | + /** |
|
| 188 | + * Strips all whitespace from the string, replacing it with |
|
| 189 | + * regular spaces (newlines, tabs, etc.). |
|
| 190 | + * |
|
| 191 | + * @param string $string |
|
| 192 | + * @return string |
|
| 193 | + */ |
|
| 194 | 194 | protected function stripWhitespace(string $string) : string |
| 195 | 195 | { |
| 196 | 196 | return preg_replace('/[\s]/', ' ', $string); |
@@ -18,23 +18,23 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __construct(array $size) |
| 20 | 20 | { |
| 21 | - if(!isset($size['width'])) { |
|
| 21 | + if (!isset($size['width'])) { |
|
| 22 | 22 | $size['width'] = $size[0]; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if(!isset($size['height'])) { |
|
| 25 | + if (!isset($size['height'])) { |
|
| 26 | 26 | $size['height'] = $size[1]; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if(!isset($size[0])) { |
|
| 29 | + if (!isset($size[0])) { |
|
| 30 | 30 | $size[0] = $size['width']; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if(!isset($size[1])) { |
|
| 33 | + if (!isset($size[1])) { |
|
| 34 | 34 | $size[1] = $size['height']; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if(!isset($size['channels'])) { |
|
| 37 | + if (!isset($size['channels'])) { |
|
| 38 | 38 | $size['channels'] = 1; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function offsetGet($offset) |
| 70 | 70 | { |
| 71 | - if(isset($this->size[$offset])) { |
|
| 71 | + if (isset($this->size[$offset])) { |
|
| 72 | 72 | return $this->size[$offset]; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | public function offsetSet($offset, $value) |
| 79 | 79 | { |
| 80 | - if(is_null($offset)) { |
|
| 80 | + if (is_null($offset)) { |
|
| 81 | 81 | $this->size[] = $value; |
| 82 | 82 | } else { |
| 83 | 83 | $this->size[$offset] = $value; |
@@ -7,9 +7,9 @@ |
||
| 7 | 7 | * @author Sebastian Mordziol <[email protected]> |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Examples environment config |
|
| 12 | - */ |
|
| 10 | + /** |
|
| 11 | + * Examples environment config |
|
| 12 | + */ |
|
| 13 | 13 | require_once '../prepend.php'; |
| 14 | 14 | |
| 15 | 15 | use function AppUtils\parseURL; |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | <br> |
| 43 | 43 | <?php |
| 44 | 44 | |
| 45 | - foreach($urls as $url) |
|
| 45 | + foreach ($urls as $url) |
|
| 46 | 46 | { |
| 47 | 47 | $info = parseURL($url); |
| 48 | 48 | |
@@ -17,33 +17,33 @@ |
||
| 17 | 17 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The composer autoloader |
|
| 22 | - */ |
|
| 20 | + /** |
|
| 21 | + * The composer autoloader |
|
| 22 | + */ |
|
| 23 | 23 | require_once $autoload; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Translation global function. |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 25 | + /** |
|
| 26 | + * Translation global function. |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | 29 | function t() |
| 30 | 30 | { |
| 31 | 31 | return call_user_func_array('\AppLocalize\t', func_get_args()); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Translation global function. |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 34 | + /** |
|
| 35 | + * Translation global function. |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | 38 | function pt() |
| 39 | 39 | { |
| 40 | 40 | return call_user_func_array('\AppLocalize\pt', func_get_args()); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Translation global function. |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 43 | + /** |
|
| 44 | + * Translation global function. |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | 47 | function pts() |
| 48 | 48 | { |
| 49 | 49 | return call_user_func_array('\AppLocalize\pts', func_get_args()); |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | $autoload = realpath($root.'/../vendor/autoload.php'); |
| 13 | 13 | |
| 14 | 14 | // we need the autoloader to be present |
| 15 | - if($autoload === false) |
|
| 15 | + if ($autoload === false) |
|
| 16 | 16 | { |
| 17 | 17 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 18 | 18 | } |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Creates and returns a new instance of the CSV builder which |
|
| 55 | - * can be used to build CSV from scratch. |
|
| 56 | - * |
|
| 57 | - * @return CSVHelper_Builder |
|
| 58 | - */ |
|
| 53 | + /** |
|
| 54 | + * Creates and returns a new instance of the CSV builder which |
|
| 55 | + * can be used to build CSV from scratch. |
|
| 56 | + * |
|
| 57 | + * @return CSVHelper_Builder |
|
| 58 | + */ |
|
| 59 | 59 | public static function createBuilder() |
| 60 | 60 | { |
| 61 | 61 | return new CSVHelper_Builder(); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | 67 | protected $csv = ''; |
| 68 | 68 | |
| 69 | 69 | protected $data = array(); |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | protected $headersPosition = self::HEADERS_NONE; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Loads CSV data from a string. |
|
| 77 | - * |
|
| 78 | - * Note: Use the {@link hasErrors()} method to |
|
| 79 | - * check if the string could be parsed correctly |
|
| 80 | - * afterwards. |
|
| 81 | - * |
|
| 82 | - * @param string $string |
|
| 83 | - * @return CSVHelper |
|
| 84 | - */ |
|
| 75 | + /** |
|
| 76 | + * Loads CSV data from a string. |
|
| 77 | + * |
|
| 78 | + * Note: Use the {@link hasErrors()} method to |
|
| 79 | + * check if the string could be parsed correctly |
|
| 80 | + * afterwards. |
|
| 81 | + * |
|
| 82 | + * @param string $string |
|
| 83 | + * @return CSVHelper |
|
| 84 | + */ |
|
| 85 | 85 | public function loadString($string) |
| 86 | 86 | { |
| 87 | 87 | // remove any UTF byte order marks that may still be present in the string |
@@ -95,20 +95,20 @@ discard block |
||
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Loads CSV data from a file. |
|
| 100 | - * |
|
| 101 | - * Note: Use the {@link hasErrors()} method to |
|
| 102 | - * check if the string could be parsed correctly |
|
| 103 | - * afterwards. |
|
| 104 | - * |
|
| 105 | - * @param string $file |
|
| 106 | - * @throws FileHelper_Exception |
|
| 107 | - * @return CSVHelper |
|
| 108 | - * |
|
| 109 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 110 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 111 | - */ |
|
| 98 | + /** |
|
| 99 | + * Loads CSV data from a file. |
|
| 100 | + * |
|
| 101 | + * Note: Use the {@link hasErrors()} method to |
|
| 102 | + * check if the string could be parsed correctly |
|
| 103 | + * afterwards. |
|
| 104 | + * |
|
| 105 | + * @param string $file |
|
| 106 | + * @throws FileHelper_Exception |
|
| 107 | + * @return CSVHelper |
|
| 108 | + * |
|
| 109 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 110 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 111 | + */ |
|
| 112 | 112 | public function loadFile(string $file) : CSVHelper |
| 113 | 113 | { |
| 114 | 114 | $csv = FileHelper::readContents($file); |
@@ -122,28 +122,28 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | protected $rowCount = 0; |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Specifies that headers are positioned on top, horizontally. |
|
| 127 | - * @return CSVHelper |
|
| 128 | - */ |
|
| 125 | + /** |
|
| 126 | + * Specifies that headers are positioned on top, horizontally. |
|
| 127 | + * @return CSVHelper |
|
| 128 | + */ |
|
| 129 | 129 | public function setHeadersTop() |
| 130 | 130 | { |
| 131 | 131 | return $this->setHeadersPosition(self::HEADERS_TOP); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Specifies that headers are positioned on the left, vertically. |
|
| 136 | - * @return CSVHelper |
|
| 137 | - */ |
|
| 134 | + /** |
|
| 135 | + * Specifies that headers are positioned on the left, vertically. |
|
| 136 | + * @return CSVHelper |
|
| 137 | + */ |
|
| 138 | 138 | public function setHeadersLeft() |
| 139 | 139 | { |
| 140 | 140 | return $this->setHeadersPosition(self::HEADERS_LEFT); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Specifies that there are no headers in the file (default). |
|
| 145 | - * @return CSVHelper |
|
| 146 | - */ |
|
| 143 | + /** |
|
| 144 | + * Specifies that there are no headers in the file (default). |
|
| 145 | + * @return CSVHelper |
|
| 146 | + */ |
|
| 147 | 147 | public function setHeadersNone() |
| 148 | 148 | { |
| 149 | 149 | return $this->setHeadersPosition(self::HEADERS_NONE); |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Specifies where the headers are positioned in the |
|
| 178 | - * CSV, or turns them off entirely. Use the class constants |
|
| 179 | - * to ensure the value is correct. |
|
| 180 | - * |
|
| 181 | - * @param string $position |
|
| 182 | - * @throws CSVHelper_Exception |
|
| 183 | - * @return CSVHelper |
|
| 184 | - * @see CSVHelper::HEADERS_LEFT |
|
| 185 | - * @see CSVHelper::HEADERS_TOP |
|
| 186 | - * @see CSVHelper::HEADERS_NONE |
|
| 187 | - */ |
|
| 176 | + /** |
|
| 177 | + * Specifies where the headers are positioned in the |
|
| 178 | + * CSV, or turns them off entirely. Use the class constants |
|
| 179 | + * to ensure the value is correct. |
|
| 180 | + * |
|
| 181 | + * @param string $position |
|
| 182 | + * @throws CSVHelper_Exception |
|
| 183 | + * @return CSVHelper |
|
| 184 | + * @see CSVHelper::HEADERS_LEFT |
|
| 185 | + * @see CSVHelper::HEADERS_TOP |
|
| 186 | + * @see CSVHelper::HEADERS_NONE |
|
| 187 | + */ |
|
| 188 | 188 | public function setHeadersPosition($position) |
| 189 | 189 | { |
| 190 | 190 | $validPositions = array( |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | return $this; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Resets all internal data, allowing to start entirely anew |
|
| 216 | - * with a new file, or to start building a new CSV file from |
|
| 217 | - * scratch. |
|
| 218 | - * |
|
| 219 | - * @return CSVHelper |
|
| 220 | - */ |
|
| 214 | + /** |
|
| 215 | + * Resets all internal data, allowing to start entirely anew |
|
| 216 | + * with a new file, or to start building a new CSV file from |
|
| 217 | + * scratch. |
|
| 218 | + * |
|
| 219 | + * @return CSVHelper |
|
| 220 | + */ |
|
| 221 | 221 | public function reset() |
| 222 | 222 | { |
| 223 | 223 | $this->data = array(); |
@@ -234,19 +234,19 @@ discard block |
||
| 234 | 234 | return $this->data; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Retrieves the row at the specified index. |
|
| 239 | - * If there is no data at the index, this will |
|
| 240 | - * return an array populated with empty strings |
|
| 241 | - * for all available columns. |
|
| 242 | - * |
|
| 243 | - * Tip: Use the {@link rowExists()} method to check |
|
| 244 | - * whether the specified row exists. |
|
| 245 | - * |
|
| 246 | - * @param integer $index |
|
| 247 | - * @return array() |
|
| 248 | - * @see rowExists() |
|
| 249 | - */ |
|
| 237 | + /** |
|
| 238 | + * Retrieves the row at the specified index. |
|
| 239 | + * If there is no data at the index, this will |
|
| 240 | + * return an array populated with empty strings |
|
| 241 | + * for all available columns. |
|
| 242 | + * |
|
| 243 | + * Tip: Use the {@link rowExists()} method to check |
|
| 244 | + * whether the specified row exists. |
|
| 245 | + * |
|
| 246 | + * @param integer $index |
|
| 247 | + * @return array() |
|
| 248 | + * @see rowExists() |
|
| 249 | + */ |
|
| 250 | 250 | public function getRow($index) |
| 251 | 251 | { |
| 252 | 252 | if(isset($this->data[$index])) { |
@@ -256,63 +256,63 @@ discard block |
||
| 256 | 256 | return array_fill(0, $this->rowCount, ''); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Checks whether the specified row exists in the data set. |
|
| 261 | - * @param integer $index |
|
| 262 | - * @return boolean |
|
| 263 | - */ |
|
| 259 | + /** |
|
| 260 | + * Checks whether the specified row exists in the data set. |
|
| 261 | + * @param integer $index |
|
| 262 | + * @return boolean |
|
| 263 | + */ |
|
| 264 | 264 | public function rowExists($index) |
| 265 | 265 | { |
| 266 | 266 | return isset($this->data[$index]); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Counts the amount of rows in the parsed CSV, |
|
| 271 | - * excluding the headers if any, depending on |
|
| 272 | - * their position. |
|
| 273 | - * |
|
| 274 | - * @return integer |
|
| 275 | - */ |
|
| 269 | + /** |
|
| 270 | + * Counts the amount of rows in the parsed CSV, |
|
| 271 | + * excluding the headers if any, depending on |
|
| 272 | + * their position. |
|
| 273 | + * |
|
| 274 | + * @return integer |
|
| 275 | + */ |
|
| 276 | 276 | public function countRows() |
| 277 | 277 | { |
| 278 | 278 | return $this->rowCount; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Counts the amount of rows in the parsed CSV, |
|
| 283 | - * excluding the headers if any, depending on |
|
| 284 | - * their position. |
|
| 285 | - * |
|
| 286 | - * @return integer |
|
| 287 | - */ |
|
| 281 | + /** |
|
| 282 | + * Counts the amount of rows in the parsed CSV, |
|
| 283 | + * excluding the headers if any, depending on |
|
| 284 | + * their position. |
|
| 285 | + * |
|
| 286 | + * @return integer |
|
| 287 | + */ |
|
| 288 | 288 | public function countColumns() |
| 289 | 289 | { |
| 290 | 290 | return $this->columnCount; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Retrieves the headers, if any. Specify the position of the |
|
| 295 | - * headers first to ensure this works correctly. |
|
| 296 | - * |
|
| 297 | - * @return array Indexed array with header names. |
|
| 298 | - */ |
|
| 293 | + /** |
|
| 294 | + * Retrieves the headers, if any. Specify the position of the |
|
| 295 | + * headers first to ensure this works correctly. |
|
| 296 | + * |
|
| 297 | + * @return array Indexed array with header names. |
|
| 298 | + */ |
|
| 299 | 299 | public function getHeaders() |
| 300 | 300 | { |
| 301 | 301 | return $this->headers; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Retrieves the column at the specified index. If there |
|
| 306 | - * is no column at the index, this returns an array |
|
| 307 | - * populated with empty strings. |
|
| 308 | - * |
|
| 309 | - * Tip: Use the {@link columnExists()} method to check |
|
| 310 | - * whether a column exists. |
|
| 311 | - * |
|
| 312 | - * @param integer $index |
|
| 313 | - * @return string[] |
|
| 314 | - * @see columnExists() |
|
| 315 | - */ |
|
| 304 | + /** |
|
| 305 | + * Retrieves the column at the specified index. If there |
|
| 306 | + * is no column at the index, this returns an array |
|
| 307 | + * populated with empty strings. |
|
| 308 | + * |
|
| 309 | + * Tip: Use the {@link columnExists()} method to check |
|
| 310 | + * whether a column exists. |
|
| 311 | + * |
|
| 312 | + * @param integer $index |
|
| 313 | + * @return string[] |
|
| 314 | + * @see columnExists() |
|
| 315 | + */ |
|
| 316 | 316 | public function getColumn($index) |
| 317 | 317 | { |
| 318 | 318 | $data = array(); |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | return $data; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * Checks whether the specified column exists in the data set. |
|
| 333 | - * @param integer $index |
|
| 334 | - * @return boolean |
|
| 335 | - */ |
|
| 331 | + /** |
|
| 332 | + * Checks whether the specified column exists in the data set. |
|
| 333 | + * @param integer $index |
|
| 334 | + * @return boolean |
|
| 335 | + */ |
|
| 336 | 336 | public function columnExists($index) |
| 337 | 337 | { |
| 338 | 338 | if($index < $this->columnCount) { |
@@ -396,22 +396,22 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Checks whether any errors have been encountered |
|
| 401 | - * while parsing the CSV. |
|
| 402 | - * |
|
| 403 | - * @return boolean |
|
| 404 | - * @see getErrorMessages() |
|
| 405 | - */ |
|
| 399 | + /** |
|
| 400 | + * Checks whether any errors have been encountered |
|
| 401 | + * while parsing the CSV. |
|
| 402 | + * |
|
| 403 | + * @return boolean |
|
| 404 | + * @see getErrorMessages() |
|
| 405 | + */ |
|
| 406 | 406 | public function hasErrors() |
| 407 | 407 | { |
| 408 | 408 | return !empty($this->errors); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * Retrieves all error messages. |
|
| 413 | - * @return array |
|
| 414 | - */ |
|
| 411 | + /** |
|
| 412 | + * Retrieves all error messages. |
|
| 413 | + * @return array |
|
| 414 | + */ |
|
| 415 | 415 | public function getErrorMessages() |
| 416 | 416 | { |
| 417 | 417 | return $this->errors; |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | public function isHeadersPosition($position) |
| 172 | 172 | { |
| 173 | - if($this->headersPosition === $position) { |
|
| 173 | + if ($this->headersPosition === $position) { |
|
| 174 | 174 | return true; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | self::HEADERS_TOP |
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | - if(!in_array($position, $validPositions)) { |
|
| 200 | + if (!in_array($position, $validPositions)) { |
|
| 201 | 201 | throw new CSVHelper_Exception( |
| 202 | 202 | 'Invalid headers position', |
| 203 | 203 | sprintf( |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function getRow($index) |
| 255 | 255 | { |
| 256 | - if(isset($this->data[$index])) { |
|
| 256 | + if (isset($this->data[$index])) { |
|
| 257 | 257 | return $this->data[$index]; |
| 258 | 258 | } |
| 259 | 259 | |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | public function getColumn($index) |
| 321 | 321 | { |
| 322 | 322 | $data = array(); |
| 323 | - for($i=0; $i < $this->rowCount; $i++) { |
|
| 323 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
| 324 | 324 | $value = ''; |
| 325 | - if(isset($this->data[$i][$index])) { |
|
| 325 | + if (isset($this->data[$i][$index])) { |
|
| 326 | 326 | $value = $this->data[$i][$index]; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | public function columnExists($index) |
| 341 | 341 | { |
| 342 | - if($index < $this->columnCount) { |
|
| 342 | + if ($index < $this->columnCount) { |
|
| 343 | 343 | return true; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | { |
| 351 | 351 | $this->reset(); |
| 352 | 352 | |
| 353 | - if(empty(trim($this->csv))) { |
|
| 353 | + if (empty(trim($this->csv))) { |
|
| 354 | 354 | $this->addError('Tried to parse an empty CSV string.'); |
| 355 | 355 | return; |
| 356 | 356 | } |
@@ -362,14 +362,14 @@ discard block |
||
| 362 | 362 | |
| 363 | 363 | $parser = self::createParser(); |
| 364 | 364 | |
| 365 | - if(!$parser->parse($this->csv)) { |
|
| 365 | + if (!$parser->parse($this->csv)) { |
|
| 366 | 366 | $this->addError('The CSV string could not be parsed.'); |
| 367 | 367 | return; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $result = $parser->data; |
| 371 | 371 | |
| 372 | - switch($this->headersPosition) |
|
| 372 | + switch ($this->headersPosition) |
|
| 373 | 373 | { |
| 374 | 374 | case self::HEADERS_TOP: |
| 375 | 375 | $this->headers = array_shift($result); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | case self::HEADERS_LEFT: |
| 379 | 379 | $keep = array(); |
| 380 | 380 | $total = count($result); |
| 381 | - for($i=0; $i < $total; $i++) { |
|
| 381 | + for ($i = 0; $i < $total; $i++) { |
|
| 382 | 382 | $row = $result[$i]; |
| 383 | 383 | $this->headers[] = array_shift($row); |
| 384 | 384 | $keep[] = $row; |
@@ -391,9 +391,9 @@ discard block |
||
| 391 | 391 | $this->data = $result; |
| 392 | 392 | $this->rowCount = count($this->data); |
| 393 | 393 | |
| 394 | - for($i=0; $i < $this->rowCount; $i++) { |
|
| 394 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
| 395 | 395 | $amount = count($this->data[$i]); |
| 396 | - if($amount > $this->columnCount) { |
|
| 396 | + if ($amount > $this->columnCount) { |
|
| 397 | 397 | $this->columnCount = $amount; |
| 398 | 398 | } |
| 399 | 399 | } |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | ',,' => ',' |
| 438 | 438 | ); |
| 439 | 439 | |
| 440 | - foreach($search as $char => $separator) { |
|
| 441 | - if(strstr($this->csv, $char)) { |
|
| 440 | + foreach ($search as $char => $separator) { |
|
| 441 | + if (strstr($this->csv, $char)) { |
|
| 442 | 442 | return $separator; |
| 443 | 443 | } |
| 444 | 444 | } |
@@ -452,11 +452,11 @@ discard block |
||
| 452 | 452 | * @param string $delimiter |
| 453 | 453 | * @return Csv |
| 454 | 454 | */ |
| 455 | - public static function createParser(string $delimiter=self::DELIMITER_AUTO) : Csv |
|
| 455 | + public static function createParser(string $delimiter = self::DELIMITER_AUTO) : Csv |
|
| 456 | 456 | { |
| 457 | 457 | $csv = new Csv(); |
| 458 | 458 | |
| 459 | - if($delimiter !== self::DELIMITER_AUTO) { |
|
| 459 | + if ($delimiter !== self::DELIMITER_AUTO) { |
|
| 460 | 460 | $csv->delimiter = $delimiter; |
| 461 | 461 | } |
| 462 | 462 | |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $parser = self::createParser(); |
| 483 | 483 | $result = $parser->parse($path); |
| 484 | 484 | |
| 485 | - if($result === true) { |
|
| 485 | + if ($result === true) { |
|
| 486 | 486 | return $parser->data; |
| 487 | 487 | } |
| 488 | 488 | |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $parser = self::createParser(); |
| 513 | 513 | $result = $parser->parse($string); |
| 514 | 514 | |
| 515 | - if($result === true) { |
|
| 515 | + if ($result === true) { |
|
| 516 | 516 | return $parser->data; |
| 517 | 517 | } |
| 518 | 518 | |