@@ -26,39 +26,39 @@ discard block |
||
| 26 | 26 | const ERROR_NO_DATE_FROM_SET = 43401; |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | 32 | protected $dateFrom; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var int |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var int |
|
| 36 | + */ |
|
| 37 | 37 | protected $dateTo; |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var bool |
|
| 41 | - */ |
|
| 39 | + /** |
|
| 40 | + * @var bool |
|
| 41 | + */ |
|
| 42 | 42 | protected $future = false; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | 47 | protected $interval = ''; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | 52 | protected $difference = 0; |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var int |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var int |
|
| 56 | + */ |
|
| 57 | 57 | protected $dateDiff = 0; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var array|NULL |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var array|NULL |
|
| 61 | + */ |
|
| 62 | 62 | protected static $texts = null; |
| 63 | 63 | |
| 64 | 64 | public function __construct() |
@@ -78,17 +78,17 @@ discard block |
||
| 78 | 78 | self::$texts = null; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Sets the origin date to calculate from. |
|
| 83 | - * |
|
| 84 | - * NOTE: if this is further in the future than |
|
| 85 | - * the to: date, it will be considered as a |
|
| 86 | - * calculation for something to come, i.e. |
|
| 87 | - * "In two days". |
|
| 88 | - * |
|
| 89 | - * @param \DateTime $date |
|
| 90 | - * @return ConvertHelper_DurationConverter |
|
| 91 | - */ |
|
| 81 | + /** |
|
| 82 | + * Sets the origin date to calculate from. |
|
| 83 | + * |
|
| 84 | + * NOTE: if this is further in the future than |
|
| 85 | + * the to: date, it will be considered as a |
|
| 86 | + * calculation for something to come, i.e. |
|
| 87 | + * "In two days". |
|
| 88 | + * |
|
| 89 | + * @param \DateTime $date |
|
| 90 | + * @return ConvertHelper_DurationConverter |
|
| 91 | + */ |
|
| 92 | 92 | public function setDateFrom(\DateTime $date) : ConvertHelper_DurationConverter |
| 93 | 93 | { |
| 94 | 94 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | return $this; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Sets the date to calculate to. Defaults to |
|
| 101 | - * the current time if not set. |
|
| 102 | - * |
|
| 103 | - * @param \DateTime $date |
|
| 104 | - * @return ConvertHelper_DurationConverter |
|
| 105 | - */ |
|
| 99 | + /** |
|
| 100 | + * Sets the date to calculate to. Defaults to |
|
| 101 | + * the current time if not set. |
|
| 102 | + * |
|
| 103 | + * @param \DateTime $date |
|
| 104 | + * @return ConvertHelper_DurationConverter |
|
| 105 | + */ |
|
| 106 | 106 | public function setDateTo(\DateTime $date) : ConvertHelper_DurationConverter |
| 107 | 107 | { |
| 108 | 108 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | return $this; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Converts the specified dates to a human readable string. |
|
| 115 | - * |
|
| 116 | - * @throws ConvertHelper_Exception |
|
| 117 | - * @return string |
|
| 118 | - * |
|
| 119 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 120 | - */ |
|
| 113 | + /** |
|
| 114 | + * Converts the specified dates to a human readable string. |
|
| 115 | + * |
|
| 116 | + * @throws ConvertHelper_Exception |
|
| 117 | + * @return string |
|
| 118 | + * |
|
| 119 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 120 | + */ |
|
| 121 | 121 | public function convert() : string |
| 122 | 122 | { |
| 123 | 123 | $this->initTexts(); |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | const BASE_2 = 1024; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var ConvertHelper_StorageSizeEnum_Size[]|NULL |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var ConvertHelper_StorageSizeEnum_Size[]|NULL |
|
| 36 | + */ |
|
| 37 | 37 | protected static $sizes = null; |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initializes the supported unit notations, and |
|
| 41 | - * how they are supposed to be calculated. |
|
| 42 | - * |
|
| 43 | - * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | - */ |
|
| 39 | + /** |
|
| 40 | + * Initializes the supported unit notations, and |
|
| 41 | + * how they are supposed to be calculated. |
|
| 42 | + * |
|
| 43 | + * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | + */ |
|
| 45 | 45 | protected static function init() |
| 46 | 46 | { |
| 47 | 47 | if(isset(self::$sizes)) { |
@@ -70,30 +70,30 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Called whenever the application locale is changed, |
|
| 75 | - * to reset the size definitions so the labels get |
|
| 76 | - * translated to the new locale. |
|
| 77 | - * |
|
| 78 | - * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
| 79 | - */ |
|
| 73 | + /** |
|
| 74 | + * Called whenever the application locale is changed, |
|
| 75 | + * to reset the size definitions so the labels get |
|
| 76 | + * translated to the new locale. |
|
| 77 | + * |
|
| 78 | + * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
| 79 | + */ |
|
| 80 | 80 | public static function handle_localeChanged(\AppLocalize\Localization_Event_LocaleChanged $event) |
| 81 | 81 | { |
| 82 | 82 | self::$sizes = null; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Adds a storage size to the internal collection. |
|
| 87 | - * |
|
| 88 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 89 | - * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 90 | - * @param int $exponent The multiplier of the base to get the byte value |
|
| 91 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 92 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 93 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 94 | - * |
|
| 95 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 96 | - */ |
|
| 85 | + /** |
|
| 86 | + * Adds a storage size to the internal collection. |
|
| 87 | + * |
|
| 88 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 89 | + * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 90 | + * @param int $exponent The multiplier of the base to get the byte value |
|
| 91 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 92 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 93 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 94 | + * |
|
| 95 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 96 | + */ |
|
| 97 | 97 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
| 98 | 98 | { |
| 99 | 99 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Retrieves all known sizes. |
|
| 111 | - * |
|
| 112 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 113 | - */ |
|
| 109 | + /** |
|
| 110 | + * Retrieves all known sizes. |
|
| 111 | + * |
|
| 112 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 113 | + */ |
|
| 114 | 114 | public static function getSizes() |
| 115 | 115 | { |
| 116 | 116 | self::init(); |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | return self::$sizes; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Retrieves a size definition instance by its name. |
|
| 123 | - * |
|
| 124 | - * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 125 | - * @throws ConvertHelper_Exception |
|
| 126 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 127 | - * |
|
| 128 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 129 | - */ |
|
| 121 | + /** |
|
| 122 | + * Retrieves a size definition instance by its name. |
|
| 123 | + * |
|
| 124 | + * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 125 | + * @throws ConvertHelper_Exception |
|
| 126 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 127 | + * |
|
| 128 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 129 | + */ |
|
| 130 | 130 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
| 131 | 131 | { |
| 132 | 132 | self::init(); |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 151 | + /** |
|
| 152 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | 155 | public static function getSizeNames() : array |
| 156 | 156 | { |
| 157 | 157 | self::init(); |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | return array_keys(self::$sizes); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Retrieves all available storage sizes for the specified |
|
| 164 | - * base value. |
|
| 165 | - * |
|
| 166 | - * @param int $base |
|
| 167 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 168 | - * |
|
| 169 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 170 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 171 | - */ |
|
| 162 | + /** |
|
| 163 | + * Retrieves all available storage sizes for the specified |
|
| 164 | + * base value. |
|
| 165 | + * |
|
| 166 | + * @param int $base |
|
| 167 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 168 | + * |
|
| 169 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 170 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 171 | + */ |
|
| 172 | 172 | public static function getSizesByBase(int $base) |
| 173 | 173 | { |
| 174 | 174 | self::init(); |
@@ -29,56 +29,56 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | const ERROR_CURL_INIT_FAILED = 17903; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $eol = "\r\n"; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $mimeBoundary; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $data = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | 50 | protected $destination; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | 55 | protected $headers = array(); |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Whether to verify SSL certificates. |
|
| 59 | - * @var bool |
|
| 60 | - */ |
|
| 57 | + /** |
|
| 58 | + * Whether to verify SSL certificates. |
|
| 59 | + * @var bool |
|
| 60 | + */ |
|
| 61 | 61 | protected $verifySSL = true; |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var RequestHelper_Boundaries |
|
| 65 | - */ |
|
| 63 | + /** |
|
| 64 | + * @var RequestHelper_Boundaries |
|
| 65 | + */ |
|
| 66 | 66 | protected $boundaries; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var RequestHelper_Response|NULL |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var RequestHelper_Response|NULL |
|
| 70 | + */ |
|
| 71 | 71 | protected $response; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var integer |
|
| 75 | - */ |
|
| 73 | + /** |
|
| 74 | + * @var integer |
|
| 75 | + */ |
|
| 76 | 76 | protected $timeout = 30; |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
| 80 | - * @param string $destinationURL |
|
| 81 | - */ |
|
| 78 | + /** |
|
| 79 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
| 80 | + * @param string $destinationURL |
|
| 81 | + */ |
|
| 82 | 82 | public function __construct(string $destinationURL) |
| 83 | 83 | { |
| 84 | 84 | $this->destination = $destinationURL; |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Adds a file to be sent with the request. |
|
| 110 | - * |
|
| 111 | - * @param string $varName The variable name to send the file in |
|
| 112 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 113 | - * @param string $content The raw content of the file |
|
| 114 | - * @param string $contentType The content type, use the constants to specify this |
|
| 115 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 116 | - */ |
|
| 108 | + /** |
|
| 109 | + * Adds a file to be sent with the request. |
|
| 110 | + * |
|
| 111 | + * @param string $varName The variable name to send the file in |
|
| 112 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 113 | + * @param string $content The raw content of the file |
|
| 114 | + * @param string $contentType The content type, use the constants to specify this |
|
| 115 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 116 | + */ |
|
| 117 | 117 | public function addFile(string $varName, string $fileName, string $content, string $contentType = self::FILETYPE_TEXT, string $encoding = self::ENCODING_UTF8) : RequestHelper |
| 118 | 118 | { |
| 119 | 119 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | return $this; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Adds arbitrary content. |
|
| 126 | - * |
|
| 127 | - * @param string $varName The variable name to send the content in. |
|
| 128 | - * @param string $content |
|
| 129 | - * @param string $contentType |
|
| 130 | - */ |
|
| 124 | + /** |
|
| 125 | + * Adds arbitrary content. |
|
| 126 | + * |
|
| 127 | + * @param string $varName The variable name to send the content in. |
|
| 128 | + * @param string $content |
|
| 129 | + * @param string $contentType |
|
| 130 | + */ |
|
| 131 | 131 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
| 132 | 132 | { |
| 133 | 133 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | return $this; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Sets an HTTP header to include in the request. |
|
| 154 | - * |
|
| 155 | - * @param string $name |
|
| 156 | - * @param string $value |
|
| 157 | - * @return RequestHelper |
|
| 158 | - */ |
|
| 152 | + /** |
|
| 153 | + * Sets an HTTP header to include in the request. |
|
| 154 | + * |
|
| 155 | + * @param string $name |
|
| 156 | + * @param string $value |
|
| 157 | + * @return RequestHelper |
|
| 158 | + */ |
|
| 159 | 159 | public function setHeader(string $name, string $value) : RequestHelper |
| 160 | 160 | { |
| 161 | 161 | $this->headers[$name] = $value; |
@@ -163,36 +163,36 @@ discard block |
||
| 163 | 163 | return $this; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Disables SSL certificate checking. |
|
| 168 | - * |
|
| 169 | - * @return RequestHelper |
|
| 170 | - */ |
|
| 166 | + /** |
|
| 167 | + * Disables SSL certificate checking. |
|
| 168 | + * |
|
| 169 | + * @return RequestHelper |
|
| 170 | + */ |
|
| 171 | 171 | public function disableSSLChecks() : RequestHelper |
| 172 | 172 | { |
| 173 | 173 | $this->verifySSL = false; |
| 174 | 174 | return $this; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @var integer |
|
| 179 | - */ |
|
| 177 | + /** |
|
| 178 | + * @var integer |
|
| 179 | + */ |
|
| 180 | 180 | protected $contentLength = 0; |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Sends the POST request to the destination, and returns |
|
| 184 | - * the response text. |
|
| 185 | - * |
|
| 186 | - * The response object is stored internally, so after calling |
|
| 187 | - * this method it may be retrieved at any moment using the |
|
| 188 | - * {@link getResponse()} method. |
|
| 189 | - * |
|
| 190 | - * @return string |
|
| 191 | - * @see RequestHelper::getResponse() |
|
| 192 | - * @throws RequestHelper_Exception |
|
| 193 | - * |
|
| 194 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 195 | - */ |
|
| 182 | + /** |
|
| 183 | + * Sends the POST request to the destination, and returns |
|
| 184 | + * the response text. |
|
| 185 | + * |
|
| 186 | + * The response object is stored internally, so after calling |
|
| 187 | + * this method it may be retrieved at any moment using the |
|
| 188 | + * {@link getResponse()} method. |
|
| 189 | + * |
|
| 190 | + * @return string |
|
| 191 | + * @see RequestHelper::getResponse() |
|
| 192 | + * @throws RequestHelper_Exception |
|
| 193 | + * |
|
| 194 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 195 | + */ |
|
| 196 | 196 | public function send() : string |
| 197 | 197 | { |
| 198 | 198 | $this->data = $this->boundaries->render(); |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | return $this->data; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Creates a new CURL resource configured according to the |
|
| 237 | - * request's settings. |
|
| 238 | - * |
|
| 239 | - * @param URLInfo $url |
|
| 240 | - * @throws RequestHelper_Exception |
|
| 241 | - * @return resource |
|
| 242 | - */ |
|
| 235 | + /** |
|
| 236 | + * Creates a new CURL resource configured according to the |
|
| 237 | + * request's settings. |
|
| 238 | + * |
|
| 239 | + * @param URLInfo $url |
|
| 240 | + * @throws RequestHelper_Exception |
|
| 241 | + * @return resource |
|
| 242 | + */ |
|
| 243 | 243 | protected function createCURL(URLInfo $url) |
| 244 | 244 | { |
| 245 | 245 | $ch = curl_init(); |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | return $ch; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Compiles the associative headers array into |
|
| 284 | - * the format understood by CURL, namely an indexed |
|
| 285 | - * array with one header string per entry. |
|
| 286 | - * |
|
| 287 | - * @return array |
|
| 288 | - */ |
|
| 282 | + /** |
|
| 283 | + * Compiles the associative headers array into |
|
| 284 | + * the format understood by CURL, namely an indexed |
|
| 285 | + * array with one header string per entry. |
|
| 286 | + * |
|
| 287 | + * @return array |
|
| 288 | + */ |
|
| 289 | 289 | protected function renderHeaders() : array |
| 290 | 290 | { |
| 291 | 291 | $result = array(); |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | return $result; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Retrieves the raw response header, in the form of an indexed |
|
| 302 | - * array containing all response header lines. |
|
| 303 | - * |
|
| 304 | - * @return array |
|
| 305 | - */ |
|
| 300 | + /** |
|
| 301 | + * Retrieves the raw response header, in the form of an indexed |
|
| 302 | + * array containing all response header lines. |
|
| 303 | + * |
|
| 304 | + * @return array |
|
| 305 | + */ |
|
| 306 | 306 | public function getResponseHeader() : array |
| 307 | 307 | { |
| 308 | 308 | $response = $this->getResponse(); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | // CURL will complain about an empty response when the |
| 211 | 211 | // server sends a 100-continue code. That should not be |
| 212 | 212 | // regarded as an error. |
| 213 | - if($output === false && $this->response->getCode() !== 100) |
|
| 213 | + if ($output === false && $this->response->getCode() !== 100) |
|
| 214 | 214 | { |
| 215 | 215 | $this->response->setError( |
| 216 | 216 | curl_errno($ch), |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | protected function createCURL(URLInfo $url) |
| 244 | 244 | { |
| 245 | 245 | $ch = curl_init(); |
| 246 | - if(!is_resource($ch)) |
|
| 246 | + if (!is_resource($ch)) |
|
| 247 | 247 | { |
| 248 | 248 | throw new RequestHelper_Exception( |
| 249 | 249 | 'Could not initialize a new cURL instance.', |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
| 256 | - $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary=' . $this->mimeBoundary); |
|
| 256 | + $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary='.$this->mimeBoundary); |
|
| 257 | 257 | |
| 258 | 258 | //curl_setopt($ch, CURLOPT_VERBOSE, true); |
| 259 | 259 | curl_setopt($ch, CURLOPT_POST, true); |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 265 | 265 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->renderHeaders()); |
| 266 | 266 | |
| 267 | - if($this->verifySSL) |
|
| 267 | + if ($this->verifySSL) |
|
| 268 | 268 | { |
| 269 | 269 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 270 | 270 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if($url->hasUsername()) |
|
| 273 | + if ($url->hasUsername()) |
|
| 274 | 274 | { |
| 275 | 275 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
| 276 | 276 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | { |
| 291 | 291 | $result = array(); |
| 292 | 292 | |
| 293 | - foreach($this->headers as $name => $value) { |
|
| 293 | + foreach ($this->headers as $name => $value) { |
|
| 294 | 294 | $result[] = $name.': '.$value; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | { |
| 308 | 308 | $response = $this->getResponse(); |
| 309 | 309 | |
| 310 | - if($response !== null) { |
|
| 310 | + if ($response !== null) { |
|
| 311 | 311 | return $response->getHeaders(); |
| 312 | 312 | } |
| 313 | 313 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $contents = file_get_contents($file); |
| 108 | 108 | |
| 109 | - if($contents === false) |
|
| 109 | + if ($contents === false) |
|
| 110 | 110 | { |
| 111 | 111 | throw new FileHelper_Exception( |
| 112 | 112 | 'Cannot load serialized content from file.', |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $result = @unserialize($contents); |
| 122 | 122 | |
| 123 | - if($result !== false) { |
|
| 123 | + if ($result !== false) { |
|
| 124 | 124 | return $result; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | public static function deleteTree($rootFolder) |
| 138 | 138 | { |
| 139 | - if(!file_exists($rootFolder)) { |
|
| 139 | + if (!file_exists($rootFolder)) { |
|
| 140 | 140 | return true; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public static function createFolder($path) |
| 179 | 179 | { |
| 180 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
| 180 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
| 181 | 181 | return; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | if ($item->isDir()) |
| 214 | 214 | { |
| 215 | - FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
|
| 215 | + FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName); |
|
| 216 | 216 | } |
| 217 | - else if($item->isFile()) |
|
| 217 | + else if ($item->isFile()) |
|
| 218 | 218 | { |
| 219 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
| 219 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | { |
| 242 | 242 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
| 243 | 243 | |
| 244 | - if(!is_readable($sourcePath)) |
|
| 244 | + if (!is_readable($sourcePath)) |
|
| 245 | 245 | { |
| 246 | 246 | throw new FileHelper_Exception( |
| 247 | 247 | sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)), |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $targetFolder = dirname($targetPath); |
| 257 | 257 | |
| 258 | - if(!file_exists($targetFolder)) |
|
| 258 | + if (!file_exists($targetFolder)) |
|
| 259 | 259 | { |
| 260 | 260 | self::createFolder($targetFolder); |
| 261 | 261 | } |
| 262 | - else if(!is_writable($targetFolder)) |
|
| 262 | + else if (!is_writable($targetFolder)) |
|
| 263 | 263 | { |
| 264 | 264 | throw new FileHelper_Exception( |
| 265 | 265 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if(copy($sourcePath, $targetPath)) { |
|
| 274 | + if (copy($sourcePath, $targetPath)) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -298,11 +298,11 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public static function deleteFile(string $filePath) : void |
| 300 | 300 | { |
| 301 | - if(!file_exists($filePath)) { |
|
| 301 | + if (!file_exists($filePath)) { |
|
| 302 | 302 | return; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if(unlink($filePath)) { |
|
| 305 | + if (unlink($filePath)) { |
|
| 306 | 306 | return; |
| 307 | 307 | } |
| 308 | 308 | |
@@ -326,10 +326,10 @@ discard block |
||
| 326 | 326 | * @return \parseCSV |
| 327 | 327 | * @todo Move this to the CSV helper. |
| 328 | 328 | */ |
| 329 | - public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV |
|
| 329 | + public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV |
|
| 330 | 330 | { |
| 331 | - if($delimiter==='') { $delimiter = ';'; } |
|
| 332 | - if($enclosure==='') { $enclosure = '"'; } |
|
| 331 | + if ($delimiter === '') { $delimiter = ';'; } |
|
| 332 | + if ($enclosure === '') { $enclosure = '"'; } |
|
| 333 | 333 | |
| 334 | 334 | $parser = new \parseCSV(null, null, null, array()); |
| 335 | 335 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * @see parseCSVFile() |
| 358 | 358 | * @see FileHelper::ERROR_PARSING_CSV |
| 359 | 359 | */ |
| 360 | - public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
| 360 | + public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
| 361 | 361 | { |
| 362 | 362 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
| 363 | 363 | $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv); |
| 364 | - if(is_array($result)) { |
|
| 364 | + if (is_array($result)) { |
|
| 365 | 365 | return $result; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 391 | 391 | * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
| 392 | 392 | */ |
| 393 | - public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
| 393 | + public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
| 394 | 394 | { |
| 395 | 395 | $content = self::readContents($filePath); |
| 396 | 396 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | public static function detectMimeType(string $fileName) : ?string |
| 408 | 408 | { |
| 409 | 409 | $ext = self::getExtension($fileName); |
| 410 | - if(empty($ext)) { |
|
| 410 | + if (empty($ext)) { |
|
| 411 | 411 | return null; |
| 412 | 412 | } |
| 413 | 413 | |
@@ -428,11 +428,11 @@ discard block |
||
| 428 | 428 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 429 | 429 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 430 | 430 | */ |
| 431 | - public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true) |
|
| 431 | + public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true) |
|
| 432 | 432 | { |
| 433 | 433 | self::requireFileExists($filePath); |
| 434 | 434 | |
| 435 | - if(empty($fileName)) { |
|
| 435 | + if (empty($fileName)) { |
|
| 436 | 436 | $fileName = basename($filePath); |
| 437 | 437 | } |
| 438 | 438 | |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | header("Cache-Control: public", true); |
| 452 | 452 | header("Content-Description: File Transfer", true); |
| 453 | - header("Content-Type: " . $mime, true); |
|
| 453 | + header("Content-Type: ".$mime, true); |
|
| 454 | 454 | |
| 455 | 455 | $disposition = 'inline'; |
| 456 | - if($asAttachment) { |
|
| 456 | + if ($asAttachment) { |
|
| 457 | 457 | $disposition = 'attachment'; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | requireCURL(); |
| 482 | 482 | |
| 483 | 483 | $ch = curl_init(); |
| 484 | - if(!is_resource($ch)) |
|
| 484 | + if (!is_resource($ch)) |
|
| 485 | 485 | { |
| 486 | 486 | throw new FileHelper_Exception( |
| 487 | 487 | 'Could not initialize a new cURL instance.', |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | $output = curl_exec($ch); |
| 504 | 504 | |
| 505 | - if($output === false) { |
|
| 505 | + if ($output === false) { |
|
| 506 | 506 | throw new FileHelper_Exception( |
| 507 | 507 | 'Unable to open URL', |
| 508 | 508 | sprintf( |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | |
| 517 | 517 | curl_close($ch); |
| 518 | 518 | |
| 519 | - if(is_string($output)) |
|
| 519 | + if (is_string($output)) |
|
| 520 | 520 | { |
| 521 | 521 | return $output; |
| 522 | 522 | } |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | public static function isPHPFile($pathOrDirIterator) |
| 540 | 540 | { |
| 541 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
| 541 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
| 542 | 542 | return true; |
| 543 | 543 | } |
| 544 | 544 | |
@@ -555,14 +555,14 @@ discard block |
||
| 555 | 555 | */ |
| 556 | 556 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
| 557 | 557 | { |
| 558 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 558 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 559 | 559 | $filename = $pathOrDirIterator->getFilename(); |
| 560 | 560 | } else { |
| 561 | 561 | $filename = basename($pathOrDirIterator); |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 565 | - if($lowercase) { |
|
| 565 | + if ($lowercase) { |
|
| 566 | 566 | $ext = mb_strtolower($ext); |
| 567 | 567 | } |
| 568 | 568 | |
@@ -584,13 +584,13 @@ discard block |
||
| 584 | 584 | public static function getFilename($pathOrDirIterator, $extension = true) |
| 585 | 585 | { |
| 586 | 586 | $path = $pathOrDirIterator; |
| 587 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 587 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 588 | 588 | $path = $pathOrDirIterator->getFilename(); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | $path = self::normalizePath($path); |
| 592 | 592 | |
| 593 | - if(!$extension) { |
|
| 593 | + if (!$extension) { |
|
| 594 | 594 | return pathinfo($path, PATHINFO_FILENAME); |
| 595 | 595 | } |
| 596 | 596 | |
@@ -608,12 +608,12 @@ discard block |
||
| 608 | 608 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 609 | 609 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 610 | 610 | */ |
| 611 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
| 611 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
| 612 | 612 | { |
| 613 | 613 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
| 614 | 614 | |
| 615 | 615 | $content = file_get_contents($file); |
| 616 | - if(!$content) { |
|
| 616 | + if (!$content) { |
|
| 617 | 617 | throw new FileHelper_Exception( |
| 618 | 618 | 'Cannot get file contents', |
| 619 | 619 | sprintf( |
@@ -624,12 +624,12 @@ discard block |
||
| 624 | 624 | ); |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - if(isset($targetEncoding)) { |
|
| 627 | + if (isset($targetEncoding)) { |
|
| 628 | 628 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | $json = json_decode($content, true); |
| 632 | - if($json === false || $json === NULL) { |
|
| 632 | + if ($json === false || $json === NULL) { |
|
| 633 | 633 | throw new FileHelper_Exception( |
| 634 | 634 | 'Cannot decode json data', |
| 635 | 635 | sprintf( |
@@ -669,13 +669,13 @@ discard block |
||
| 669 | 669 | |
| 670 | 670 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 671 | 671 | |
| 672 | - while(strstr($name, ' ')) { |
|
| 672 | + while (strstr($name, ' ')) { |
|
| 673 | 673 | $name = str_replace(' ', ' ', $name); |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 677 | 677 | |
| 678 | - while(strstr($name, '..')) { |
|
| 678 | + while (strstr($name, '..')) { |
|
| 679 | 679 | $name = str_replace('..', '.', $name); |
| 680 | 680 | } |
| 681 | 681 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @return array An indexed array with files. |
| 708 | 708 | * @see FileHelper::createFileFinder() |
| 709 | 709 | */ |
| 710 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
| 710 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
| 711 | 711 | { |
| 712 | 712 | return self::findFiles($targetFolder, array('html'), $options); |
| 713 | 713 | } |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * @return array An indexed array of PHP files. |
| 725 | 725 | * @see FileHelper::createFileFinder() |
| 726 | 726 | */ |
| 727 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
| 727 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
| 728 | 728 | { |
| 729 | 729 | return self::findFiles($targetFolder, array('php'), $options); |
| 730 | 730 | } |
@@ -744,22 +744,22 @@ discard block |
||
| 744 | 744 | * @return array |
| 745 | 745 | * @see FileHelper::createFileFinder() |
| 746 | 746 | */ |
| 747 | - public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
|
| 747 | + public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array |
|
| 748 | 748 | { |
| 749 | 749 | $finder = self::createFileFinder($targetFolder); |
| 750 | 750 | |
| 751 | 751 | $finder->setPathmodeStrip(); |
| 752 | 752 | |
| 753 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 753 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 754 | 754 | { |
| 755 | 755 | $finder->setPathmodeRelative(); |
| 756 | 756 | } |
| 757 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 757 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 758 | 758 | { |
| 759 | 759 | $finder->setPathmodeAbsolute(); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if(isset($options['strip-extension'])) |
|
| 762 | + if (isset($options['strip-extension'])) |
|
| 763 | 763 | { |
| 764 | 764 | $finder->stripExtensions(); |
| 765 | 765 | } |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | public static function detectUTFBom(string $filename) : ?string |
| 804 | 804 | { |
| 805 | 805 | $fp = fopen($filename, 'r'); |
| 806 | - if($fp === false) |
|
| 806 | + if ($fp === false) |
|
| 807 | 807 | { |
| 808 | 808 | throw new FileHelper_Exception( |
| 809 | 809 | 'Cannot open file for reading', |
@@ -818,10 +818,10 @@ discard block |
||
| 818 | 818 | |
| 819 | 819 | $boms = self::getUTFBOMs(); |
| 820 | 820 | |
| 821 | - foreach($boms as $bom => $value) |
|
| 821 | + foreach ($boms as $bom => $value) |
|
| 822 | 822 | { |
| 823 | 823 | $length = mb_strlen($value); |
| 824 | - if(mb_substr($text, 0, $length) == $value) { |
|
| 824 | + if (mb_substr($text, 0, $length) == $value) { |
|
| 825 | 825 | return $bom; |
| 826 | 826 | } |
| 827 | 827 | } |
@@ -840,13 +840,13 @@ discard block |
||
| 840 | 840 | */ |
| 841 | 841 | public static function getUTFBOMs() |
| 842 | 842 | { |
| 843 | - if(!isset(self::$utfBoms)) { |
|
| 843 | + if (!isset(self::$utfBoms)) { |
|
| 844 | 844 | self::$utfBoms = array( |
| 845 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
| 846 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
| 847 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
| 848 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
| 849 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
| 845 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
| 846 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
| 847 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
| 848 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
| 849 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
| 850 | 850 | ); |
| 851 | 851 | } |
| 852 | 852 | |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | $encodings = self::getKnownUnicodeEncodings(); |
| 868 | 868 | |
| 869 | 869 | $keep = array(); |
| 870 | - foreach($encodings as $string) |
|
| 870 | + foreach ($encodings as $string) |
|
| 871 | 871 | { |
| 872 | 872 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
| 873 | 873 | |
@@ -914,16 +914,16 @@ discard block |
||
| 914 | 914 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 915 | 915 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 916 | 916 | */ |
| 917 | - public static function saveAsJSON($data, string $file, bool $pretty=false) |
|
| 917 | + public static function saveAsJSON($data, string $file, bool $pretty = false) |
|
| 918 | 918 | { |
| 919 | 919 | $options = null; |
| 920 | - if($pretty) { |
|
| 920 | + if ($pretty) { |
|
| 921 | 921 | $options = JSON_PRETTY_PRINT; |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | $json = json_encode($data, $options); |
| 925 | 925 | |
| 926 | - if($json===false) |
|
| 926 | + if ($json === false) |
|
| 927 | 927 | { |
| 928 | 928 | $errorCode = json_last_error(); |
| 929 | 929 | |
@@ -949,12 +949,12 @@ discard block |
||
| 949 | 949 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 950 | 950 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 951 | 951 | */ |
| 952 | - public static function saveFile(string $filePath, string $content='') : void |
|
| 952 | + public static function saveFile(string $filePath, string $content = '') : void |
|
| 953 | 953 | { |
| 954 | 954 | // target file already exists |
| 955 | - if(file_exists($filePath)) |
|
| 955 | + if (file_exists($filePath)) |
|
| 956 | 956 | { |
| 957 | - if(!is_writable($filePath)) |
|
| 957 | + if (!is_writable($filePath)) |
|
| 958 | 958 | { |
| 959 | 959 | throw new FileHelper_Exception( |
| 960 | 960 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | // create the folder as needed |
| 975 | 975 | self::createFolder($targetFolder); |
| 976 | 976 | |
| 977 | - if(!is_writable($targetFolder)) |
|
| 977 | + if (!is_writable($targetFolder)) |
|
| 978 | 978 | { |
| 979 | 979 | throw new FileHelper_Exception( |
| 980 | 980 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | } |
| 988 | 988 | } |
| 989 | 989 | |
| 990 | - if(file_put_contents($filePath, $content) !== false) { |
|
| 990 | + if (file_put_contents($filePath, $content) !== false) { |
|
| 991 | 991 | return; |
| 992 | 992 | } |
| 993 | 993 | |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | { |
| 1026 | 1026 | static $checked = array(); |
| 1027 | 1027 | |
| 1028 | - if(isset($checked[$command])) { |
|
| 1028 | + if (isset($checked[$command])) { |
|
| 1029 | 1029 | return $checked[$command]; |
| 1030 | 1030 | } |
| 1031 | 1031 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | |
| 1039 | 1039 | $os = strtolower(PHP_OS_FAMILY); |
| 1040 | 1040 | |
| 1041 | - if(!isset($osCommands[$os])) |
|
| 1041 | + if (!isset($osCommands[$os])) |
|
| 1042 | 1042 | { |
| 1043 | 1043 | throw new FileHelper_Exception( |
| 1044 | 1044 | 'Unsupported OS for CLI commands', |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | $pipes |
| 1065 | 1065 | ); |
| 1066 | 1066 | |
| 1067 | - if($process === false) { |
|
| 1067 | + if ($process === false) { |
|
| 1068 | 1068 | $checked[$command] = false; |
| 1069 | 1069 | return false; |
| 1070 | 1070 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | */ |
| 1096 | 1096 | public static function checkPHPFileSyntax($path) |
| 1097 | 1097 | { |
| 1098 | - if(!self::canMakePHPCalls()) { |
|
| 1098 | + if (!self::canMakePHPCalls()) { |
|
| 1099 | 1099 | return true; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
@@ -1106,7 +1106,7 @@ discard block |
||
| 1106 | 1106 | // when the validation is successful, the first entry |
| 1107 | 1107 | // in the array contains the success message. When it |
| 1108 | 1108 | // is invalid, the first entry is always empty. |
| 1109 | - if(!empty($output[0])) { |
|
| 1109 | + if (!empty($output[0])) { |
|
| 1110 | 1110 | return true; |
| 1111 | 1111 | } |
| 1112 | 1112 | |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | public static function getModifiedDate($path) |
| 1128 | 1128 | { |
| 1129 | 1129 | $time = filemtime($path); |
| 1130 | - if($time !== false) { |
|
| 1130 | + if ($time !== false) { |
|
| 1131 | 1131 | $date = new \DateTime(); |
| 1132 | 1132 | $date->setTimestamp($time); |
| 1133 | 1133 | return $date; |
@@ -1156,7 +1156,7 @@ discard block |
||
| 1156 | 1156 | */ |
| 1157 | 1157 | public static function getSubfolders($targetFolder, $options = array()) |
| 1158 | 1158 | { |
| 1159 | - if(!is_dir($targetFolder)) |
|
| 1159 | + if (!is_dir($targetFolder)) |
|
| 1160 | 1160 | { |
| 1161 | 1161 | throw new FileHelper_Exception( |
| 1162 | 1162 | 'Target folder does not exist', |
@@ -1180,29 +1180,29 @@ discard block |
||
| 1180 | 1180 | |
| 1181 | 1181 | $d = new \DirectoryIterator($targetFolder); |
| 1182 | 1182 | |
| 1183 | - foreach($d as $item) |
|
| 1183 | + foreach ($d as $item) |
|
| 1184 | 1184 | { |
| 1185 | - if($item->isDir() && !$item->isDot()) |
|
| 1185 | + if ($item->isDir() && !$item->isDot()) |
|
| 1186 | 1186 | { |
| 1187 | 1187 | $name = $item->getFilename(); |
| 1188 | 1188 | |
| 1189 | - if(!$options['absolute-path']) { |
|
| 1189 | + if (!$options['absolute-path']) { |
|
| 1190 | 1190 | $result[] = $name; |
| 1191 | 1191 | } else { |
| 1192 | 1192 | $result[] = $targetFolder.'/'.$name; |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | - if(!$options['recursive']) |
|
| 1195 | + if (!$options['recursive']) |
|
| 1196 | 1196 | { |
| 1197 | 1197 | continue; |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
| 1201 | - foreach($subs as $sub) |
|
| 1201 | + foreach ($subs as $sub) |
|
| 1202 | 1202 | { |
| 1203 | 1203 | $relative = $name.'/'.$sub; |
| 1204 | 1204 | |
| 1205 | - if(!$options['absolute-path']) { |
|
| 1205 | + if (!$options['absolute-path']) { |
|
| 1206 | 1206 | $result[] = $relative; |
| 1207 | 1207 | } else { |
| 1208 | 1208 | $result[] = $targetFolder.'/'.$relative; |
@@ -1252,7 +1252,7 @@ discard block |
||
| 1252 | 1252 | $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. |
| 1253 | 1253 | $size = floatval(preg_replace('/[^0-9\.]/', '', $size)); // Remove the non-numeric characters from the size. |
| 1254 | 1254 | |
| 1255 | - if($unit) |
|
| 1255 | + if ($unit) |
|
| 1256 | 1256 | { |
| 1257 | 1257 | // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. |
| 1258 | 1258 | return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | * @param int $depth The folder depth to reduce the path to |
| 1272 | 1272 | * @return string |
| 1273 | 1273 | */ |
| 1274 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 1274 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 1275 | 1275 | { |
| 1276 | 1276 | $path = self::normalizePath($path); |
| 1277 | 1277 | |
@@ -1279,17 +1279,17 @@ discard block |
||
| 1279 | 1279 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
| 1280 | 1280 | $tokens = array_values($tokens); // re-index keys |
| 1281 | 1281 | |
| 1282 | - if(empty($tokens)) { |
|
| 1282 | + if (empty($tokens)) { |
|
| 1283 | 1283 | return ''; |
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | // remove the drive if present |
| 1287 | - if(strstr($tokens[0], ':')) { |
|
| 1287 | + if (strstr($tokens[0], ':')) { |
|
| 1288 | 1288 | array_shift($tokens); |
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | // path was only the drive |
| 1292 | - if(count($tokens) == 0) { |
|
| 1292 | + if (count($tokens) == 0) { |
|
| 1293 | 1293 | return ''; |
| 1294 | 1294 | } |
| 1295 | 1295 | |
@@ -1298,8 +1298,8 @@ discard block |
||
| 1298 | 1298 | |
| 1299 | 1299 | // reduce the path to the specified depth |
| 1300 | 1300 | $length = count($tokens); |
| 1301 | - if($length > $depth) { |
|
| 1302 | - $tokens = array_slice($tokens, $length-$depth); |
|
| 1301 | + if ($length > $depth) { |
|
| 1302 | + $tokens = array_slice($tokens, $length - $depth); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | // append the last element again |
@@ -1347,14 +1347,14 @@ discard block |
||
| 1347 | 1347 | * |
| 1348 | 1348 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 1349 | 1349 | */ |
| 1350 | - public static function requireFileExists(string $path, $errorCode=null) : string |
|
| 1350 | + public static function requireFileExists(string $path, $errorCode = null) : string |
|
| 1351 | 1351 | { |
| 1352 | 1352 | $result = realpath($path); |
| 1353 | - if($result !== false) { |
|
| 1353 | + if ($result !== false) { |
|
| 1354 | 1354 | return $result; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - if($errorCode === null) { |
|
| 1357 | + if ($errorCode === null) { |
|
| 1358 | 1358 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
| 1359 | 1359 | } |
| 1360 | 1360 | |
@@ -1383,15 +1383,15 @@ discard block |
||
| 1383 | 1383 | |
| 1384 | 1384 | $file = new \SplFileObject($path); |
| 1385 | 1385 | |
| 1386 | - if($file->eof()) { |
|
| 1386 | + if ($file->eof()) { |
|
| 1387 | 1387 | return ''; |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | - $targetLine = $lineNumber-1; |
|
| 1390 | + $targetLine = $lineNumber - 1; |
|
| 1391 | 1391 | |
| 1392 | 1392 | $file->seek($targetLine); |
| 1393 | 1393 | |
| 1394 | - if($file->key() !== $targetLine) { |
|
| 1394 | + if ($file->key() !== $targetLine) { |
|
| 1395 | 1395 | return null; |
| 1396 | 1396 | } |
| 1397 | 1397 | |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | $number = $spl->key(); |
| 1418 | 1418 | |
| 1419 | 1419 | // if seeking to the end the cursor is still at 0, there are no lines. |
| 1420 | - if($number === 0) |
|
| 1420 | + if ($number === 0) |
|
| 1421 | 1421 | { |
| 1422 | 1422 | // since it's a very small file, to get reliable results, |
| 1423 | 1423 | // we read its contents and use that to determine what |
@@ -1425,13 +1425,13 @@ discard block |
||
| 1425 | 1425 | // that this is not pactical to solve with the SplFileObject. |
| 1426 | 1426 | $content = file_get_contents($path); |
| 1427 | 1427 | |
| 1428 | - if(empty($content)) { |
|
| 1428 | + if (empty($content)) { |
|
| 1429 | 1429 | return 0; |
| 1430 | 1430 | } |
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // return the line number we were able to reach + 1 (key is zero-based) |
| 1434 | - return $number+1; |
|
| 1434 | + return $number + 1; |
|
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | /** |
@@ -1478,13 +1478,13 @@ discard block |
||
| 1478 | 1478 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 1479 | 1479 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 1480 | 1480 | */ |
| 1481 | - public static function readLines(string $filePath, int $amount=0) : array |
|
| 1481 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
| 1482 | 1482 | { |
| 1483 | 1483 | self::requireFileExists($filePath); |
| 1484 | 1484 | |
| 1485 | 1485 | $fn = fopen($filePath, "r"); |
| 1486 | 1486 | |
| 1487 | - if($fn === false) |
|
| 1487 | + if ($fn === false) |
|
| 1488 | 1488 | { |
| 1489 | 1489 | throw new FileHelper_Exception( |
| 1490 | 1490 | 'Could not open file for reading.', |
@@ -1500,19 +1500,19 @@ discard block |
||
| 1500 | 1500 | $counter = 0; |
| 1501 | 1501 | $first = true; |
| 1502 | 1502 | |
| 1503 | - while(!feof($fn)) |
|
| 1503 | + while (!feof($fn)) |
|
| 1504 | 1504 | { |
| 1505 | 1505 | $counter++; |
| 1506 | 1506 | |
| 1507 | 1507 | $line = fgets($fn); |
| 1508 | 1508 | |
| 1509 | 1509 | // can happen with zero length files |
| 1510 | - if($line === false) { |
|
| 1510 | + if ($line === false) { |
|
| 1511 | 1511 | continue; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | // the first line may contain a unicode BOM marker. |
| 1515 | - if($first) |
|
| 1515 | + if ($first) |
|
| 1516 | 1516 | { |
| 1517 | 1517 | $line = ConvertHelper::stripUTFBom($line); |
| 1518 | 1518 | $first = false; |
@@ -1520,7 +1520,7 @@ discard block |
||
| 1520 | 1520 | |
| 1521 | 1521 | $result[] = $line; |
| 1522 | 1522 | |
| 1523 | - if($amount > 0 && $counter == $amount) { |
|
| 1523 | + if ($amount > 0 && $counter == $amount) { |
|
| 1524 | 1524 | break; |
| 1525 | 1525 | } |
| 1526 | 1526 | } |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | |
| 1547 | 1547 | $result = file_get_contents($filePath); |
| 1548 | 1548 | |
| 1549 | - if($result !== false) { |
|
| 1549 | + if ($result !== false) { |
|
| 1550 | 1550 | return $result; |
| 1551 | 1551 | } |
| 1552 | 1552 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setValue($value) : NumberInfo |
| 86 | 86 | { |
| 87 | - if($value instanceof NumberInfo) { |
|
| 87 | + if ($value instanceof NumberInfo) { |
|
| 88 | 88 | $value = $value->getValue(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function isPositive() : bool |
| 119 | 119 | { |
| 120 | - if(!$this->isEmpty()) { |
|
| 120 | + if (!$this->isEmpty()) { |
|
| 121 | 121 | $number = $this->getNumber(); |
| 122 | 122 | return $number > 0; |
| 123 | 123 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function hasValue() : bool |
| 150 | 150 | { |
| 151 | - if(!$this->isEmpty() && !$this->isZero()) { |
|
| 151 | + if (!$this->isEmpty() && !$this->isZero()) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function getUnits() |
| 223 | 223 | { |
| 224 | - if(!$this->hasUnits()) { |
|
| 224 | + if (!$this->hasUnits()) { |
|
| 225 | 225 | return 'px'; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function toAttribute() : string |
| 257 | 257 | { |
| 258 | - if($this->isEmpty()) { |
|
| 258 | + if ($this->isEmpty()) { |
|
| 259 | 259 | return ''; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($this->isZero()) { |
|
| 262 | + if ($this->isZero()) { |
|
| 263 | 263 | return '0'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->isPercent()) { |
|
| 266 | + if ($this->isPercent()) { |
|
| 267 | 267 | return $this->getNumber().$this->getUnits(); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function toCSS() : string |
| 278 | 278 | { |
| 279 | - if($this->isEmpty()) { |
|
| 279 | + if ($this->isEmpty()) { |
|
| 280 | 280 | return ''; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->isZero()) { |
|
| 283 | + if ($this->isZero()) { |
|
| 284 | 284 | return '0'; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | public function __toString() |
| 291 | 291 | { |
| 292 | - if($this->isEmpty()) { |
|
| 292 | + if ($this->isEmpty()) { |
|
| 293 | 293 | return ''; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function isBiggerThan($number) |
| 308 | 308 | { |
| 309 | 309 | $number = parseNumber($number); |
| 310 | - if($number->getUnits() != $this->getUnits()) { |
|
| 310 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | public function isSmallerThan($number) |
| 326 | 326 | { |
| 327 | 327 | $number = parseNumber($number); |
| 328 | - if($number->getUnits() != $this->getUnits()) { |
|
| 328 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | public function isBiggerEqual($number) |
| 336 | 336 | { |
| 337 | 337 | $number = parseNumber($number); |
| 338 | - if($number->getUnits() != $this->getUnits()) { |
|
| 338 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function add($value) |
| 354 | 354 | { |
| 355 | - if($this->isEmpty()) { |
|
| 355 | + if ($this->isEmpty()) { |
|
| 356 | 356 | $this->setValue($value); |
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $number = parseNumber($value); |
| 361 | 361 | |
| 362 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 362 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 363 | 363 | { |
| 364 | 364 | $new = $this->getNumber() + $number->getNumber(); |
| 365 | 365 | $this->setValue($new.$this->getUnits()); |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function subtract($value) |
| 380 | 380 | { |
| 381 | - if($this->isEmpty()) { |
|
| 381 | + if ($this->isEmpty()) { |
|
| 382 | 382 | $this->setValue($value); |
| 383 | 383 | return $this; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $number = parseNumber($value); |
| 387 | 387 | |
| 388 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 388 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 389 | 389 | { |
| 390 | 390 | $new = $this->getNumber() - $number->getNumber(); |
| 391 | 391 | $this->setValue($new.$this->getUnits()); |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | protected function percentOperation($operation, $percent) |
| 414 | 414 | { |
| 415 | - if($this->isZeroOrEmpty()) { |
|
| 415 | + if ($this->isZeroOrEmpty()) { |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | $percent = parseNumber($percent); |
| 420 | - if($percent->hasUnits() && !$percent->isPercent()) { |
|
| 420 | + if ($percent->hasUnits() && !$percent->isPercent()) { |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $number = $this->getNumber(); |
| 425 | 425 | $value = $number * $percent->getNumber() / 100; |
| 426 | 426 | |
| 427 | - if($operation == '-') { |
|
| 427 | + if ($operation == '-') { |
|
| 428 | 428 | $number = $number - $value; |
| 429 | 429 | } else { |
| 430 | 430 | $number = $number + $value; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if($this->isUnitInteger()) { |
|
| 433 | + if ($this->isUnitInteger()) { |
|
| 434 | 434 | $number = intval($number); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | $key = $this->createValueKey($value); |
| 483 | 483 | |
| 484 | - if(array_key_exists($key, $cache)) { |
|
| 484 | + if (array_key_exists($key, $cache)) { |
|
| 485 | 485 | return $cache[$key]; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | 'number' => null |
| 492 | 492 | ); |
| 493 | 493 | |
| 494 | - if($key === '_EMPTY_') |
|
| 494 | + if ($key === '_EMPTY_') |
|
| 495 | 495 | { |
| 496 | 496 | $cache[$key]['empty'] = true; |
| 497 | 497 | return $cache[$key]; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - if($value === 0 || $value === '0') |
|
| 500 | + if ($value === 0 || $value === '0') |
|
| 501 | 501 | { |
| 502 | 502 | $cache[$key]['number'] = 0; |
| 503 | 503 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $test = trim((string)$value); |
| 508 | 508 | |
| 509 | - if($test === '') |
|
| 509 | + if ($test === '') |
|
| 510 | 510 | { |
| 511 | 511 | $cache[$key]['empty'] = true; |
| 512 | 512 | return $cache[$key]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // replace comma notation (which is only possible if it's a string) |
| 516 | - if(is_string($value)) |
|
| 516 | + if (is_string($value)) |
|
| 517 | 517 | { |
| 518 | 518 | $test = $this->preProcess($test, $cache, $value); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // convert to a number if it's numeric |
| 522 | - if(is_numeric($test)) |
|
| 522 | + if (is_numeric($test)) |
|
| 523 | 523 | { |
| 524 | 524 | $cache[$key]['number'] = (float)$test * 1; |
| 525 | 525 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -545,19 +545,19 @@ discard block |
||
| 545 | 545 | $empty = false; |
| 546 | 546 | |
| 547 | 547 | $found = $this->findUnits($test); |
| 548 | - if($found !== null) |
|
| 548 | + if ($found !== null) |
|
| 549 | 549 | { |
| 550 | 550 | $number = $found['number']; |
| 551 | 551 | $units = $found['units']; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | // the filters have to restore the value |
| 555 | - if($this->postProcess) |
|
| 555 | + if ($this->postProcess) |
|
| 556 | 556 | { |
| 557 | 557 | $number = $this->postProcess($number, $test); |
| 558 | 558 | } |
| 559 | 559 | // empty number |
| 560 | - else if($number === '' || $number === null || is_bool($number)) |
|
| 560 | + else if ($number === '' || $number === null || is_bool($number)) |
|
| 561 | 561 | { |
| 562 | 562 | $number = null; |
| 563 | 563 | $empty = true; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | $number = trim($number); |
| 569 | 569 | |
| 570 | 570 | // may be an arbitrary string in some cases |
| 571 | - if(!is_numeric($number)) |
|
| 571 | + if (!is_numeric($number)) |
|
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | $vlength = strlen($value); |
| 601 | 601 | $names = array_keys($this->knownUnits); |
| 602 | 602 | |
| 603 | - foreach($names as $unit) |
|
| 603 | + foreach ($names as $unit) |
|
| 604 | 604 | { |
| 605 | 605 | $ulength = strlen($unit); |
| 606 | - $start = $vlength-$ulength; |
|
| 607 | - if($start < 0) { |
|
| 606 | + $start = $vlength - $ulength; |
|
| 607 | + if ($start < 0) { |
|
| 608 | 608 | continue; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $search = substr($value, $start, $ulength); |
| 612 | 612 | |
| 613 | - if($search==$unit) |
|
| 613 | + if ($search == $unit) |
|
| 614 | 614 | { |
| 615 | 615 | return array( |
| 616 | 616 | 'units' => $unit, |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | - if(!is_string($value) && !is_numeric($value)) |
|
| 633 | + if (!is_string($value) && !is_numeric($value)) |
|
| 634 | 634 | { |
| 635 | 635 | return '_EMPTY_'; |
| 636 | 636 | } |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
| 699 | - if($info['units'] !== null) { |
|
| 699 | + if ($info['units'] !== null) { |
|
| 700 | 700 | $useUnits = $info['units']; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // the units are non-decimal: convert decimal values |
| 704 | - if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 704 | + if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 705 | 705 | { |
| 706 | 706 | $info['number'] = intval($info['number']); |
| 707 | 707 | } |