From 859a04c791b7770b18264ae1e6db1f4e77ea0aaa Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 9 Apr 2023 06:03:39 +0200 Subject: [PATCH] fix static analysis --- Account/PermissionHandlingTrait.php | 2 +- Ai/Ocr/BasicOcr.php | 54 +- Api/EUVAT/EUVATBffOnline.php | 16 +- Api/EUVAT/EUVATVies.php | 49 +- Application/ApplicationAbstract.php | 1 + Localization/ISO639CountryTrait.php | 3 - Localization/L11nManager.php | 10 +- Math/Statistic/Forecast/ARIMA/ARIMA.php | 13 + Math/Statistic/Forecast/ARIMA/SARIMA.php | 16 +- Math/Statistic/Forecast/ARIMA/SARIMAX.php | 13 + .../Forecast/BayesianStructuralTimeSeries.php | 13 + .../Forecast/DynamicLinearModels.php | 13 + .../Forecast/ExponentialSmoothing.php | 13 + Math/Statistic/Forecast/Forecasts.php | 23 +- .../Forecast/GradientBoostingMachines.php | 13 + .../Forecast/LongShortTermMemoryNetworks.php | 13 + Math/Statistic/Forecast/Prophet.php | 13 + .../Forecast/SeasonalTrendDecomposition.php | 13 + .../Forecast/VectorAutoregression.php | 13 + Message/Http/HttpHeader.php | 1 - Message/Http/HttpRequest.php | 16 +- Message/RequestAbstract.php | 21 + Model/Html/Head.php | 6 +- Security/EncryptionHelper.php | 34 +- Security/Guard.php | 6 +- Stdlib/Graph/Graph.php | 37 +- System/File/Ftp/Directory.php | 11 +- Utils/Barcode/BarAbstract.php | 8 +- Utils/Barcode/Datamatrix.php | 7 +- Utils/Barcode/QR.php | 469 ++++++++++++++++-- Utils/Barcode/TwoDAbstract.php | 9 +- Utils/Parser/Calendar/ICalParser.php | 2 + .../Presentation/PresentationWriter.php | 61 ++- Views/View.php | 7 +- 34 files changed, 867 insertions(+), 132 deletions(-) diff --git a/Account/PermissionHandlingTrait.php b/Account/PermissionHandlingTrait.php index b445b7859..0da0235a1 100755 --- a/Account/PermissionHandlingTrait.php +++ b/Account/PermissionHandlingTrait.php @@ -123,7 +123,7 @@ trait PermissionHandlingTrait * * @param int $permission Permission to check * @param null|int $unit Unit Unit to check (null if all are acceptable) - * @param null|int $app App App to check (null if all are acceptable) + * @param null|int $app App App to check (null if all are acceptable) * @param null|string $module Module Module to check (null if all are acceptable) * @param null|int $category Type (e.g. customer) (null if all are acceptable) * @param null|int $element (e.g. customer id) (null if all are acceptable) diff --git a/Ai/Ocr/BasicOcr.php b/Ai/Ocr/BasicOcr.php index 632513167..238767f5d 100755 --- a/Ai/Ocr/BasicOcr.php +++ b/Ai/Ocr/BasicOcr.php @@ -239,31 +239,66 @@ final class BasicOcr return $dist; } + /** + * Create MNIST file from images + * + * @param string[] $images Images + * @param string $out Output file + * @param int $resolution Resolution of the iomages + * + * @return void + * + * @since 1.0.0 + */ public static function imagesToMNIST(array $images, string $out, int $resolution) : void { $out = \fopen($out, 'wb'); + if ($out === false) { + return; // @codeCoverageIgnore + } \fwrite($out, \pack('N', 2051)); \fwrite($out, \pack('N', 1)); \fwrite($out, \pack('N', $resolution)); \fwrite($out, \pack('N', $resolution)); + $size = $resolution * $resolution; + foreach ($images as $in) { - $im = \imagecreatefromstring(\file_get_contents($in)); + $inString = \file_get_contents($in); + if ($inString === false) { + continue; + } + + $im = \imagecreatefromstring($inString); + if ($im === false) { + continue; + } + $new = \imagescale($im, $resolution, $resolution); + if ($new === false) { + continue; + } // Convert the image to grayscale and normalize the pixel values $mnist = []; for ($i = 0; $i < $resolution; ++$i) { for ($j = 0; $j < $resolution; ++$j) { $pixel = \imagecolorat($new, $j, $i); - $gray = \round((0.299 * (($pixel >> 16) & 0xFF) + 0.587 * (($pixel >> 8) & 0xFF) + 0.114 * ($pixel & 0xFF)) / 255, 3); + $gray = \round( + ( + 0.299 * (($pixel >> 16) & 0xFF) + + 0.587 * (($pixel >> 8) & 0xFF) + + 0.114 * ($pixel & 0xFF) + ) / 255, + 3 + ); \array_push($mnist, $gray); } } - for ($i = 0; $i < \count($mnist); $i++) { + for ($i = 0; $i < $size; $i++) { \fwrite($out, \pack('C', \round($mnist[$i] * 255))); } } @@ -271,10 +306,23 @@ final class BasicOcr \fclose($out); } + /** + * Convert labels to MNIST format + * + * @param string[] $data Labels (one char per label) + * @param string $out Output path + * + * @return void + * + * @since 1.0.0 + */ public static function labelsToMNIST(array $data, string $out) : void { // Only allows single char labels $out = \fopen($out, 'wb'); + if ($out === false) { + return; // @codeCoverageIgnore + } \fwrite($out, \pack('N', 2049)); \fwrite($out, \pack('N', 1)); diff --git a/Api/EUVAT/EUVATBffOnline.php b/Api/EUVAT/EUVATBffOnline.php index 638522252..5adf745da 100644 --- a/Api/EUVAT/EUVATBffOnline.php +++ b/Api/EUVAT/EUVATBffOnline.php @@ -44,9 +44,6 @@ final class EUVATBffOnline implements EUVATInterface */ public static function validate(string $otherVAT, string $ownVAT = '') : array { - $request = new HttpRequest(new HttpUri('https://evatr.bff-online.de/evatrRPC?UstId_1=' . $ownVAT . '&UstId_2=' . $otherVAT)); - $request->setMethod(RequestMethod::GET); - $result = [ 'status' => -1, 'vat' => 'C', @@ -57,6 +54,17 @@ final class EUVATBffOnline implements EUVATInterface 'body' => '', ]; + if (empty($otherVAT) || empty($ownVAT)) { + return $result; + } + + $request = new HttpRequest( + new HttpUri( + 'https://evatr.bff-online.de/evatrRPC?UstId_1=' . $ownVAT . '&UstId_2=' . $otherVAT + ) + ); + $request->setMethod(RequestMethod::GET); + $matches = []; try { $body = Rest::request($request)->getBody(); @@ -102,7 +110,7 @@ final class EUVATBffOnline implements EUVATInterface 'body' => '', ]; - if (empty($ownVAT)) { + if (empty($otherVAT) || empty($ownVAT)) { return $result; } diff --git a/Api/EUVAT/EUVATVies.php b/Api/EUVAT/EUVATVies.php index f29fc3866..ce80e0267 100644 --- a/Api/EUVAT/EUVATVies.php +++ b/Api/EUVAT/EUVATVies.php @@ -44,15 +44,6 @@ final class EUVATVies implements EUVATInterface */ public static function validate(string $otherVAT, string $ownVAT = '') : array { - $request = new HttpRequest( - new HttpUri( - 'https://ec.europa.eu/taxation_customs/vies/rest-api/ms/' . \substr($otherVAT, 0, 2) . '/vat/' . \substr($otherVAT, 2) . ( - $ownVAT !== '' ? '?requesterMemberStateCode=' . \substr($ownVAT, 0, 2) . '&requesterNumber=' . \substr($ownVAT, 2) : '' - ) - ) - ); - $request->setMethod(RequestMethod::GET); - $result = [ 'status' => -1, 'vat' => 'C', @@ -63,12 +54,25 @@ final class EUVATVies implements EUVATInterface 'body' => '', ]; + if (empty($otherVAT)) { + return $result; + } + + $request = new HttpRequest( + new HttpUri( + 'https://ec.europa.eu/taxation_customs/vies/rest-api/ms/' . \substr($otherVAT, 0, 2) . '/vat/' . \substr($otherVAT, 2) . ( + $ownVAT !== '' ? '?requesterMemberStateCode=' . \substr($ownVAT, 0, 2) . '&requesterNumber=' . \substr($ownVAT, 2) : '' + ) + ) + ); + $request->setMethod(RequestMethod::GET); + try { - $body = Rest::request($request)->getBody(); + $body = Rest::request($request)->getBody(); $result['body'] = $body; + /** @var array $json */ $json = \json_decode($body, true); - if ($json === false) { return $result; } @@ -105,10 +109,16 @@ final class EUVATVies implements EUVATInterface 'body' => '', ]; + if (empty($otherVAT)) { + return $result; + } + $request = new HttpRequest( new HttpUri( 'https://ec.europa.eu/taxation_customs/vies/rest-api/ms/' . \substr($otherVAT, 0, 2) . '/vat/' . \substr($otherVAT, 2) . ( - $ownVAT !== '' ? '?requesterMemberStateCode=' . \substr($ownVAT, 0, 2) . '&requesterNumber=' . \substr($ownVAT, 2) : '' + $ownVAT !== '' + ? '?requesterMemberStateCode=' . \substr($ownVAT, 0, 2) . '&requesterNumber=' . \substr($ownVAT, 2) + : '' ) ) ); @@ -118,8 +128,8 @@ final class EUVATVies implements EUVATInterface $body = Rest::request($request)->getBody(); $result['body'] = $body; + /** @var array $json */ $json = \json_decode($body, true); - if ($json === false) { return $result; } @@ -158,7 +168,9 @@ final class EUVATVies implements EUVATInterface if ($otherStreet === '') { $result['address'] = 'D'; - } elseif (\stripos($result['address'], $otherStreet) !== false && \levenshtein($otherStreet, $result['address'], insertion_cost: 0) / \strlen($result['address']) < 0.2) { + } elseif (\stripos($result['address'], $otherStreet) !== false + && \levenshtein($otherStreet, $result['address'], insertion_cost: 0) / \strlen($result['address']) < 0.2 + ) { $result['address'] = 'A'; } elseif ($result['address'] === '') { $result['address'] = 'C'; @@ -174,6 +186,15 @@ final class EUVATVies implements EUVATInterface return $result; } + /** + * Parse response. + * + * @param array $json JSON response + * + * @return array + * + * @since 1.0.0 + */ private static function parseResponse(array $json) : array { $result = [ diff --git a/Application/ApplicationAbstract.php b/Application/ApplicationAbstract.php index 89b3944dd..756d35809 100755 --- a/Application/ApplicationAbstract.php +++ b/Application/ApplicationAbstract.php @@ -36,6 +36,7 @@ use phpOMS\Router\RouterInterface; * and afterwards read only. * * @property string $appName + * @property int $appId * @property int $unitId * @property \phpOMS\DataStorage\Database\DatabasePool $dbPool * @property \phpOMS\Localization\L11nManager $l11nManager diff --git a/Localization/ISO639CountryTrait.php b/Localization/ISO639CountryTrait.php index e065f844f..49fd399e8 100644 --- a/Localization/ISO639CountryTrait.php +++ b/Localization/ISO639CountryTrait.php @@ -124,13 +124,10 @@ trait ISO639CountryTrait return [self::_FR, self::_AR]; case ISO3166TwoEnum::_CHL: return [self::_ES]; - break; case ISO3166TwoEnum::_CHN: return [self::_ZH]; - break; case ISO3166TwoEnum::_CXR: return [self::_EN]; - break; case ISO3166TwoEnum::_CCK: return [self::_EN]; case ISO3166TwoEnum::_COL: diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index f48553eb6..ba2c873e4 100755 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -257,11 +257,11 @@ final class L11nManager /** * Print a currency * - * @param Localization $l11n Localization - * @param int|float|Money $currency Currency value to print - * @param null|string $symbol Currency name/symbol - * @param null|string $format Format type to use - * @param int $divide Divide currency by divisor + * @param Localization $l11n Localization + * @param int|float|Money $currency Currency value to print + * @param null|string $symbol Currency name/symbol + * @param null|string $format Format type to use + * @param int $divide Divide currency by divisor * * @return string * diff --git a/Math/Statistic/Forecast/ARIMA/ARIMA.php b/Math/Statistic/Forecast/ARIMA/ARIMA.php index e69de29bb..af16fa04c 100644 --- a/Math/Statistic/Forecast/ARIMA/ARIMA.php +++ b/Math/Statistic/Forecast/ARIMA/ARIMA.php @@ -0,0 +1,13 @@ + $history History + * @param int $periods Number of periods to forecast + * @param int $seasonality Seasonality + * + * @return array + * + * @since 1.0.0 + */ public static function simpleSeasonalForecast(array $history, int $periods, int $seasonality = 1) : array { - $avg = \array_sum($history) / \count($history); + $size = \count($history); + $avg = \array_sum($history) / $size; $variance = 0; foreach ($history as $sale) { $variance += \pow($sale - $avg, 2); } - $variance /= \count($history); + $variance /= $size; $stdDeviation = \sqrt($variance); // Calculate the seasonal index for each period $seasonalIndex = []; for ($i = 0; $i < $seasonality; $i++) { $seasonalIndex[$i] = 0; - $count = 0; + $count = 0; - for ($j = $i; $j < \count($history); $j += $seasonality) { + + for ($j = $i; $j < $size; $j += $seasonality) { $seasonalIndex[$i] += $history[$j]; $count++; } @@ -73,7 +86,7 @@ final class Forecasts $forecast = []; for ($i = 1; $i <= $periods; $i++) { $seasonalMultiplier = $seasonalIndex[($i - 1) % $seasonality]; - $forecast[] = $avg * $seasonalMultiplier + ($stdDeviation * $i); + $forecast[] = $avg * $seasonalMultiplier + ($stdDeviation * $i); } return $forecast; diff --git a/Math/Statistic/Forecast/GradientBoostingMachines.php b/Math/Statistic/Forecast/GradientBoostingMachines.php index e69de29bb..af16fa04c 100644 --- a/Math/Statistic/Forecast/GradientBoostingMachines.php +++ b/Math/Statistic/Forecast/GradientBoostingMachines.php @@ -0,0 +1,13 @@ +set('Status', 'Status: HTTP/1.0 599 Network connect timeout error'); \http_response_code(599); } - } diff --git a/Message/Http/HttpRequest.php b/Message/Http/HttpRequest.php index 273c281e1..cbe51b744 100755 --- a/Message/Http/HttpRequest.php +++ b/Message/Http/HttpRequest.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\Message\Http; +use phpOMS\Localization\ISO3166TwoEnum; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Localization\Localization; use phpOMS\Message\RequestAbstract; use phpOMS\Router\RouteVerb; @@ -381,11 +383,13 @@ final class HttpRequest extends RequestAbstract $firstLocalComponents = \explode('-', $locals[0]); // @codeCoverageIgnoreEnd - return \strtolower($firstLocalComponents[0]); // @codeCoverageIgnore + $language = \strtolower($firstLocalComponents[0]); + + return ISO639x1Enum::isValidValue($language) ? $language : 'en'; } /** - * Get request language + * Get request country * * @return string * @@ -406,7 +410,9 @@ final class HttpRequest extends RequestAbstract $firstLocalComponents = \explode('-', $locals[0]); // @codeCoverageIgnoreEnd - return \strtoupper($firstLocalComponents[1] ?? ''); // @codeCoverageIgnore + $country = \strtoupper($firstLocalComponents[1] ?? ''); + + return ISO3166TwoEnum::isValidValue($country) ? $country : 'US'; } /** @@ -423,8 +429,8 @@ final class HttpRequest extends RequestAbstract } // @codeCoverageIgnoreStart - $components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']); - $locals = \stripos($components[0], ',') !== false + $components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components; // @codeCoverageIgnoreEnd diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 2c131152b..97973ac6f 100755 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -116,6 +116,18 @@ abstract class RequestAbstract implements MessageInterface } } + /** + * Get data. + * + * @return array + * + * @since 1.0.0 + */ + public function getDataArray() : array + { + return $this->data; + } + /** * Get data. * @@ -398,6 +410,15 @@ abstract class RequestAbstract implements MessageInterface return $this->files; } + /** + * Get files by name. + * + * @param string $name File name + * + * @return array + * + * @since 1.0.0 + */ public function getFile(string $name) : array { return $this->files[$name] ?? []; diff --git a/Model/Html/Head.php b/Model/Html/Head.php index 92cf0b8a2..6396d3797 100755 --- a/Model/Html/Head.php +++ b/Model/Html/Head.php @@ -117,9 +117,9 @@ final class Head implements RenderableInterface /** * Add tag. * - * @param int $type Asset type - * @param string $content Asset content - * @param array $attributes Asset attributes + * @param string $tag Html tag type + * @param string $content Tag content + * @param array $attributes Tag attributes * * @return void * diff --git a/Security/EncryptionHelper.php b/Security/EncryptionHelper.php index 299f1f924..57321c18c 100644 --- a/Security/EncryptionHelper.php +++ b/Security/EncryptionHelper.php @@ -51,15 +51,19 @@ final class EncryptionHelper public static function encryptShared(string $message, string $keyHex) : string { $secretKey = \sodium_hex2bin($keyHex); - $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); + $nonce = \random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); $ciphertext = \sodium_crypto_secretbox($message, $nonce, $secretKey); $result = \sodium_bin2base64($nonce . $ciphertext, SODIUM_BASE64_VARIANT_ORIGINAL); - \sodium_memzero($message); \sodium_memzero($nonce); \sodium_memzero($secretKey); + \sodium_memzero($ciphertext); + + /* + \sodium_memzero($message); \sodium_memzero($keyHex); + */ return $result; } @@ -88,6 +92,10 @@ final class EncryptionHelper \sodium_memzero($secretKey); \sodium_memzero($ciphertext); + /* + \sodium_memzero($keyHex); + */ + return $plaintext === false ? '' : $plaintext; } @@ -133,15 +141,22 @@ final class EncryptionHelper $publicKey = \sodium_hex2bin($publicKeyHex); $key = \sodium_crypto_box_keypair_from_secretkey_and_publickey($privateKey, $publicKey); - $nonce = random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES); + $nonce = \random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES); $ciphertext = \sodium_crypto_box($message, $nonce, $key); $result = \sodium_bin2base64($nonce . $ciphertext, SODIUM_BASE64_VARIANT_ORIGINAL); - \sodium_memzero($message); + \sodium_memzero($key); \sodium_memzero($nonce); - \sodium_memzero($secretKey); - \sodium_memzero($secretKeyHex); + \sodium_memzero($ciphertext); + \sodium_memzero($privateKey); + \sodium_memzero($publicKey); + + /* + \sodium_memzero($message); + \sodium_memzero($privateKeyHex); + \sodium_memzero($publicKeyHex); + */ return $result; } @@ -174,6 +189,13 @@ final class EncryptionHelper \sodium_memzero($ciphertext); \sodium_memzero($nonce); \sodium_memzero($privateKey); + \sodium_memzero($publicKey); + + /* + \sodium_memzero($message); + \sodium_memzero($privateKeyHex); + \sodium_memzero($publicKeyHex); + */ return $plaintext === false ? '' : $plaintext; } diff --git a/Security/Guard.php b/Security/Guard.php index eb7c6e197..97ca09b32 100644 --- a/Security/Guard.php +++ b/Security/Guard.php @@ -56,9 +56,11 @@ final class Guard /** * Remove slashes from a string or array * - * @param string|array $data Data to unslash + * @template T of string|array * - * @return string|array + * @param T $data Data to unslash + * + * @return (T is string ? string : array) * * @since 1.0.0 */ diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index 3b8104161..37daf94d1 100755 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -636,10 +636,10 @@ class Graph /** * Perform depth first traversal * - * @param Node $node Graph node - * @param array $visited Is the node already visited - * @param array $path Array of nodes (a path through the graph = connected nodes) - * @param array $longestPath Array of nodes (longest path through the graph = connected nodes) + * @param Node $node Graph node + * @param array $visited Is the node already visited + * @param array $path Array of nodes (a path through the graph = connected nodes) + * @param array $longestPath Array of nodes (longest path through the graph = connected nodes) * * @return void * @@ -648,7 +648,7 @@ class Graph private function longestPathDfs(Node $node, &$visited, &$path, &$longestPath) { $visited[$node->getId()] = true; - $path[] = $node; + $path[] = $node; $edges = $node->getEdges(); foreach ($edges as $edge) { @@ -912,7 +912,7 @@ class Graph $distances[$i->getId()] = 0; while (!empty($stack)) { - $current = \array_shift($queue); + $current = \array_shift($stack); foreach ($this->nodes as $j) { // Has neighbour @@ -923,7 +923,10 @@ class Graph } elseif (!$j->isEqual($i) && !$j->isEqual($current) && $distances[$j->getId()] >= $distances[$current->getId()] ) { - $girs = \min($girth, $distances[$current->getId()] + $distances[$j->getId()] + 1); + $girth = \min( + $girth, + $distances[$current->getId()] + $distances[$j->getId()] + 1 + ); } } } @@ -962,6 +965,18 @@ class Graph return $rank; } + /** + * Get the graph circuit rank + * + * @param array $adjMatrix Adjacency matrix + * @param Node $current Current node + * @param Node $previous Previous node + * @param array $visited Visited nodes + * + * @return bool + * + * @since 1.0.0 + */ private function cycleDfs(array $adjMatrix, Node $current, ?Node $previous, &$visited) : bool { $visited[$current->getId()] = true; @@ -1090,6 +1105,10 @@ class Graph */ public function isStronglyConnected() { + if (empty($this->nodes)) { + return true; + } + $visited = []; foreach ($this->nodes as $node) { $visited[] = false; @@ -1183,6 +1202,10 @@ class Graph $node1 = $this->getNode($node1); } + if ($node1 === null) { + return true; + } + foreach ($this->nodes as $node) { $colors[$node->getId()] = 0; } diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 20ac461f7..9cae09de5 100755 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -391,7 +391,16 @@ class Directory extends FileAbstract implements DirectoryInterface continue; } - $e = []; + $e = [ + 'permission' => '', + 'number' => '', + 'user' => '', + 'group' => '', + 'size' => '', + 'month' => '', + 'day' => '', + 'time' => '', + ]; list( $e['permission'], diff --git a/Utils/Barcode/BarAbstract.php b/Utils/Barcode/BarAbstract.php index 86305bc8a..fbe14cf16 100644 --- a/Utils/Barcode/BarAbstract.php +++ b/Utils/Barcode/BarAbstract.php @@ -117,9 +117,9 @@ abstract class BarAbstract extends CodeAbstract $checksum = static::$CHECKSUM; for ($pos = 1; $pos <= $length; ++$pos) { - $activeKey = \substr($this->content, ($pos - 1), 1); + $activeKey = \substr($this->content, ($pos - 1), 1); $this->codestring .= static::$CODEARRAY[$activeKey]; - $checksum += $values[$activeKey] * $pos; + $checksum += $values[$activeKey] * $pos; } $this->codestring .= static::$CODEARRAY[$keys[($checksum - ((int) ($checksum / 103) * 103))]]; @@ -146,8 +146,8 @@ abstract class BarAbstract extends CodeAbstract throw new \Exception(); // @codeCoverageIgnore } - $black = \imagecolorallocate($image, 0, 0, 0); - $white = \imagecolorallocate($image, 255, 255, 255); + $black = \imagecolorallocate($image, 0, 0, 0); + $white = \imagecolorallocate($image, 255, 255, 255); if ($white === false || $black === false) { throw new \Exception(); // @codeCoverageIgnore diff --git a/Utils/Barcode/Datamatrix.php b/Utils/Barcode/Datamatrix.php index 416101c82..367432eb8 100755 --- a/Utils/Barcode/Datamatrix.php +++ b/Utils/Barcode/Datamatrix.php @@ -122,6 +122,9 @@ class Datamatrix extends TwoDAbstract public int $encoding = self::ENC_ASCII; + /** + * {@inheritdoc} + */ public function generateCodeArray() : array { $this->codearray = []; @@ -749,7 +752,7 @@ class Datamatrix extends TwoDAbstract // check for extended character if ($chr & 0x80) { if ($enc === self::ENC_X12) { - return false; + return []; } $chr = ($chr & 0x7f); @@ -775,7 +778,7 @@ class Datamatrix extends TwoDAbstract $temp_cw[] = 2; // shift 3 $shiftset = self::CHARSET['S3T']; } else { - return false; + return []; } $temp_cw[] = $shiftset[$chr]; diff --git a/Utils/Barcode/QR.php b/Utils/Barcode/QR.php index 82bde7fc5..77e1a3df0 100755 --- a/Utils/Barcode/QR.php +++ b/Utils/Barcode/QR.php @@ -25,12 +25,36 @@ namespace phpOMS\Utils\Barcode; */ class QR extends TwoDAbstract { + /** + * Error correction level. + * + * @var int + * @since 1.0.0 + */ public const QR_ECLEVEL_L = 0; + /** + * Error correction level. + * + * @var int + * @since 1.0.0 + */ public const QR_ECLEVEL_M = 1; + /** + * Error correction level. + * + * @var int + * @since 1.0.0 + */ public const QR_ECLEVEL_Q = 2; + /** + * Error correction level. + * + * @var int + * @since 1.0.0 + */ public const QR_ECLEVEL_H = 3; private const QRCODEDEFS = true; @@ -79,7 +103,9 @@ class QR extends TwoDAbstract /** * Alphabet-numeric convesion table. - * @protected + * + * @var array + * @since 1.0.0 */ private const AN_TABLE = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -95,7 +121,9 @@ class QR extends TwoDAbstract /** * Array Table of the capacity of symbols. * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. - * @protected + * + * @var array + * @since 1.0.0 */ private const CAPACITY = [ [ 0, 0, 0, [ 0, 0, 0, 0]], // @@ -143,7 +171,9 @@ class QR extends TwoDAbstract /** * Array Length indicator. - * @protected + * + * @var array + * @since 1.0.0 */ private const LENGTH_TABLE_BITS = [ [10, 12, 14], @@ -155,7 +185,9 @@ class QR extends TwoDAbstract /** * Array Table of the error correction code (Reed-Solomon block). * See Table 12-16 (pp.30-36), JIS X0510:2004. - * @protected + * + * @var array + * @since 1.0.0 */ private const ECC_TABLE = [ [[ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0]], // @@ -205,7 +237,9 @@ class QR extends TwoDAbstract * Array Positions of alignment patterns. * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them. * See Table 1 in Appendix E (pp.71) of JIS X0510:2004. - * @protected + * + * @var array + * @since 1.0.0 */ private const ALIGNMENT_PATTERN = [ [ 0, 0], @@ -223,7 +257,9 @@ class QR extends TwoDAbstract * Array Version information pattern (BCH coded). * See Table 1 in Appendix D (pp.68) of JIS X0510:2004. * size: [QRSPEC_VERSION_MAX - 6] - * @protected + * + * @var array + * @since 1.0.0 */ private const VERSION_PATTERN = [ 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, @@ -235,7 +271,9 @@ class QR extends TwoDAbstract /** * Array Format information - * @protected + * + * @var array + * @since 1.0.0 */ private const FORMAT_INFO = [ [0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976], @@ -262,152 +300,210 @@ class QR extends TwoDAbstract "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", ]; + /** + * Version. + * + * @var int + * @since 1.0.0 + */ protected int $version = 0; /** * Levels of error correction. See definitions for possible values. - * @protected + * + * @var int + * @since 1.0.0 */ public int $level = self::QR_ECLEVEL_L; /** * Encoding mode. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $hint = self::QR_MODE_8B; /** * Boolean flag, if true the input string will be converted to uppercase. - * @protected + * + * @var bool + * @since 1.0.0 */ protected bool $casesensitive = true; /** * Structured QR code (not supported yet). - * @protected + * + * @var int + * @since 1.0.0 */ protected int $structured = 0; /** * Mask data. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $data = []; /** * Width. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $width = 0; /** * Frame. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $frame = []; /** * X position of bit. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $x = 0; /** * Y position of bit. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $y = 0; /** * Direction. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $dir = 0; /** * Single bit value. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $bit = 0; /** * Data code. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $datacode = []; /** * Error correction code. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $ecccode = []; /** * Blocks. - * @protected + * + * @var int + * + * @since 1.0.0 */ protected int $blocks = 0; /** * Reed-Solomon blocks. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $rsblocks = []; //of RSblock /** * Counter. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $count = 0; /** * Data length. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $dataLength = 0; /** * Error correction length. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $eccLength = 0; /** * Value b1. - * @protected + * + * @var int + * @since 1.0.0 */ protected int $b1 = 0; /** * Run length. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $runLength = []; /** * Input data string. - * @protected + * + * @var string + * @since 1.0.0 */ protected string $dataStr = ''; /** * Input items. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $items = []; /** * Reed-Solomon items. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $rsitems = []; /** * Array of frames. - * @protected + * + * @var array + * @since 1.0.0 */ protected array $frames = []; + /** + * {@inheritdoc} + */ public function generateCodeArray() : array { $this->codearray = []; @@ -432,6 +528,10 @@ class QR extends TwoDAbstract /** * Convert the frame in binary form + * + * @return array + * + * @since 1.0.0 */ protected function binarize(array $frame) : array { @@ -449,6 +549,10 @@ class QR extends TwoDAbstract /** * Encode the input string to QR code + * + * @return void + * + * @since 1.0.0 */ protected function encodeString(string $string) : void { @@ -467,6 +571,10 @@ class QR extends TwoDAbstract /** * Encode mask + * + * @return void + * + * @since 1.0.0 */ protected function encodeMask(int $mask) : void { @@ -535,6 +643,10 @@ class QR extends TwoDAbstract /** * Get frame value at specified position + * + * @return int + * + * @since 1.0.0 */ protected function getFrameAt(array $at) : int { @@ -543,6 +655,10 @@ class QR extends TwoDAbstract /** * Return the next frame position + * + * @return array + * + * @since 1.0.0 */ protected function getNextPosition() : array { @@ -608,6 +724,10 @@ class QR extends TwoDAbstract /** * Initialize code. + * + * @return int + * + * @since 1.0.0 */ protected function init(array $spec) : int { @@ -665,7 +785,11 @@ class QR extends TwoDAbstract } /** - * Return Reed-Solomon block code. + * Return Reed-Solomon block + * + * @return int + * + * @since 1.0.0code. */ protected function getCode() : int { @@ -693,6 +817,10 @@ class QR extends TwoDAbstract /** * Write Format Information on frame and returns the number of black bits + * + * @return int + * + * @since 1.0.0 */ protected function writeFormatInformation(int $width, array &$frame, int $mask, int $level) : int { @@ -742,6 +870,10 @@ class QR extends TwoDAbstract /** * Return bitmask + * + * @return array + * + * @since 1.0.0 */ protected function generateMaskNo(int $maskNo, int $width, array $frame) : array { @@ -789,6 +921,10 @@ class QR extends TwoDAbstract /** * makeMaskNo + * + * @return int + * + * @since 1.0.0 */ protected function makeMaskNo(int $maskNo, int $width, array $s, array &$d, bool $maskGenOnly = false) : int { @@ -816,6 +952,10 @@ class QR extends TwoDAbstract /** * makeMask + * + * @return array + * + * @since 1.0.0 */ protected function makeMask(int $width, array $frame, int $maskNo, int $level) : array { @@ -828,6 +968,10 @@ class QR extends TwoDAbstract /** * calcN1N3 + * + * @return int + * + * @since 1.0.0 */ protected function calcN1N3(int $length) : int { @@ -861,6 +1005,10 @@ class QR extends TwoDAbstract /** * evaluateSymbol + * + * @return int + * + * @since 1.0.0 */ protected function evaluateSymbol(int $width, array $frame) : int { @@ -930,6 +1078,10 @@ class QR extends TwoDAbstract /** * mask + * + * @return array + * + * @since 1.0.0 */ protected function mask(int $width, array $frame, int $level) : array { @@ -958,8 +1110,8 @@ class QR extends TwoDAbstract $demerit += $this->evaluateSymbol($width, $mask); if ($demerit < $minDemerit) { - $minDemerit = $demerit; - $bestMask = $mask; + $minDemerit = $demerit; + $bestMask = $mask; } } @@ -968,6 +1120,10 @@ class QR extends TwoDAbstract /** * Return true if the character at specified position is a number + * + * @return bool + * + * @since 1.0.0 */ protected function isdigitat(string $str, int $pos) : bool { @@ -980,6 +1136,10 @@ class QR extends TwoDAbstract /** * Return true if the character at specified position is an alphanumeric character + * + * @return bool + * + * @since 1.0.0 */ protected function isalnumat(string $str, int $pos) : bool { @@ -992,6 +1152,10 @@ class QR extends TwoDAbstract /** * identifyMode + * + * @return int + * + * @since 1.0.0 */ protected function identifyMode(int $pos) : int { @@ -1022,6 +1186,10 @@ class QR extends TwoDAbstract /** * eatNum + * + * @return int + * + * @since 1.0.0 */ protected function eatNum() : int { @@ -1061,6 +1229,10 @@ class QR extends TwoDAbstract /** * eatAn + * + * @return int + * + * @since 1.0.0 */ protected function eatAn() : int { @@ -1107,6 +1279,10 @@ class QR extends TwoDAbstract /** * eatKanji + * + * @return int + * + * @since 1.0.0 */ protected function eatKanji() : int { @@ -1123,6 +1299,10 @@ class QR extends TwoDAbstract /** * eat8 + * + * @return int + * + * @since 1.0.0 */ protected function eat8() : int { @@ -1180,6 +1360,10 @@ class QR extends TwoDAbstract /** * splitString + * + * @return int + * + * @since 1.0.0 */ protected function splitString() : int { @@ -1193,11 +1377,9 @@ class QR extends TwoDAbstract $length = $this->eatAn(); break; case self::QR_MODE_KJ: - if ($this->hint === self::QR_MODE_KJ) { - $length = $this->eatKanji(); - } else { - $length = $this->eat8(); - } + $length = $this->hint === self::QR_MODE_KJ + ? $this->eatKanji() + : $this->eat8(); break; default: $length = $this->eat8(); @@ -1220,6 +1402,10 @@ class QR extends TwoDAbstract /** * toUpper + * + * @return string + * + * @since 1.0.0 */ protected function toUpper() : string { @@ -1227,11 +1413,14 @@ class QR extends TwoDAbstract $p = 0; while ($p < $stringLen) { - $mode = $this->identifyMode(\strlen(\substr($this->dataStr, $p)), $this->hint); + $mode = $this->identifyMode(\strlen(\substr($this->dataStr, $p))/*, $this->hint*/); + if ($mode === self::QR_MODE_KJ) { $p += 2; } else { - if (\ord($this->dataStr[$p]) >= \ord('a') && \ord($this->dataStr[$p]) <= \ord('z')) { + if (\ord($this->dataStr[$p]) >= \ord('a') + && \ord($this->dataStr[$p]) <= \ord('z') + ) { $this->dataStr[$p] = \chr(\ord($this->dataStr[$p]) - 32); } @@ -1243,6 +1432,10 @@ class QR extends TwoDAbstract /** * newInputItem + * + * @return array + * + * @since 1.0.0 */ protected function newInputItem(int $mode, int $size, array $data, array $bstream = []) : array { @@ -1266,6 +1459,10 @@ class QR extends TwoDAbstract /** * encodeModeNum + * + * @return array + * + * @since 1.0.0 */ protected function encodeModeNum(array $inputitem, int $version) : array { @@ -1300,6 +1497,10 @@ class QR extends TwoDAbstract /** * encodeModeAn + * + * @return array + * + * @since 1.0.0 */ protected function encodeModeAn(array $inputitem, int $version) : array { @@ -1327,6 +1528,10 @@ class QR extends TwoDAbstract /** * encodeMode8 + * + * @return array + * + * @since 1.0.0 */ protected function encodeMode8(array $inputitem, int $version) : array { @@ -1343,6 +1548,10 @@ class QR extends TwoDAbstract /** * encodeModeKanji + * + * @return array + * + * @since 1.0.0 */ protected function encodeModeKanji(array $inputitem, int $version) : array { @@ -1370,6 +1579,10 @@ class QR extends TwoDAbstract /** * encodeModeStructure + * + * @return array + * + * @since 1.0.0 */ protected function encodeModeStructure(array $inputitem) : array { @@ -1384,6 +1597,10 @@ class QR extends TwoDAbstract /** * encodeBitStream + * + * @return array + * + * @since 1.0.0 */ protected function encodeBitStream(array $inputitem, int $version) : array { @@ -1425,6 +1642,10 @@ class QR extends TwoDAbstract /** * Append data to an input object. * The data is copied and appended to the input object. + * + * @return array + * + * @since 1.0.0 */ protected function appendNewInputItem(array $items, int $mode, int $size, array $data) : array { @@ -1439,6 +1660,10 @@ class QR extends TwoDAbstract /** * insertStructuredAppendHeader + * + * @return array + * + * @since 1.0.0 */ protected function insertStructuredAppendHeader(array $items, int $size, int $index, int $parity) : array { @@ -1446,7 +1671,7 @@ class QR extends TwoDAbstract || $index <= 0 || $index > self::MAX_STRUCTURED_SYMBOLS ) { - return -1; + return []; } $buf = [$size, $index, $parity]; @@ -1459,6 +1684,10 @@ class QR extends TwoDAbstract /** * calcParity + * + * @return int + * + * @since 1.0.0 */ protected function calcParity(array $items) : int { @@ -1476,6 +1705,10 @@ class QR extends TwoDAbstract /** * checkModeNum + * + * @return bool + * + * @since 1.0.0 */ protected function checkModeNum(int $size, array $data) : bool { @@ -1490,6 +1723,10 @@ class QR extends TwoDAbstract /** * Look up the alphabet-numeric conversion table (see JIS X0510:2004, pp.19). + * + * @return int + * + * @since 1.0.0 */ protected function lookAnTable(int $c) : int { @@ -1498,6 +1735,10 @@ class QR extends TwoDAbstract /** * checkModeAn + * + * @return bool + * + * @since 1.0.0 */ protected function checkModeAn(int $size, array $data) : bool { @@ -1512,6 +1753,10 @@ class QR extends TwoDAbstract /** * estimateBitsModeNum + * + * @return int + * + * @since 1.0.0 */ protected function estimateBitsModeNum(int $size) : int { @@ -1532,6 +1777,10 @@ class QR extends TwoDAbstract /** * estimateBitsModeAn + * + * @return int + * + * @since 1.0.0 */ protected function estimateBitsModeAn(int $size) : int { @@ -1545,6 +1794,10 @@ class QR extends TwoDAbstract /** * estimateBitsMode8 + * + * @return int + * + * @since 1.0.0 */ protected function estimateBitsMode8(int $size) : int { @@ -1553,6 +1806,10 @@ class QR extends TwoDAbstract /** * estimateBitsModeKanji + * + * @return int + * + * @since 1.0.0 */ protected function estimateBitsModeKanji(int $size) : int { @@ -1561,6 +1818,10 @@ class QR extends TwoDAbstract /** * checkModeKanji + * + * @return bool + * + * @since 1.0.0 */ protected function checkModeKanji(int $size, array $data) : bool { @@ -1580,6 +1841,10 @@ class QR extends TwoDAbstract /** * Validate the input data. + * + * @return bool + * + * @since 1.0.0 */ protected function check(int $mode, int $size, array $data) : bool { @@ -1605,6 +1870,10 @@ class QR extends TwoDAbstract /** * estimateBitStreamSize + * + * @return int + * + * @since 1.0.0 */ protected function estimateBitStreamSize(array $items, int $version) : int { @@ -1644,6 +1913,10 @@ class QR extends TwoDAbstract /** * estimateVersion + * + * @return int + * + * @since 1.0.0 */ protected function estimateVersion(array $items) : int { @@ -1665,6 +1938,10 @@ class QR extends TwoDAbstract /** * lengthOfCode + * + * @return int + * + * @since 1.0.0 */ protected function lengthOfCode(int $mode, int $version, int $bits) : int { @@ -1720,6 +1997,10 @@ class QR extends TwoDAbstract /** * createBitStream + * + * @return array + * + * @since 1.0.0 */ protected function createBitStream(array $items) : array { @@ -1735,6 +2016,10 @@ class QR extends TwoDAbstract /** * convertData + * + * @return array + * + * @since 1.0.0 */ protected function convertData(array $items) : array { @@ -1767,6 +2052,10 @@ class QR extends TwoDAbstract /** * Append Padding Bit to bitstream + * + * @return array + * + * @since 1.0.0 */ protected function appendPaddingBit(array $bstream) : array { @@ -1807,6 +2096,10 @@ class QR extends TwoDAbstract /** * mergeBitStream + * + * @return array + * + * @since 1.0.0 */ protected function mergeBitStream(array $items) : array { @@ -1825,6 +2118,10 @@ class QR extends TwoDAbstract /** * Returns a stream of bits. + * + * @return array + * + * @since 1.0.0 */ protected function getBitStream(array $items) : array { @@ -1835,6 +2132,10 @@ class QR extends TwoDAbstract /** * Pack all bit streams padding bits into a byte array. + * + * @return array + * + * @since 1.0.0 */ protected function getByteStream(array $items) : array { @@ -1845,6 +2146,10 @@ class QR extends TwoDAbstract /** * Return an array with zeros + * + * @return array + * + * @since 1.0.0 */ protected function allocate(int $setLength) : array { @@ -1853,6 +2158,10 @@ class QR extends TwoDAbstract /** * Return new bitstream from number + * + * @return array + * + * @since 1.0.0 */ protected function newFromNum(int $bits, int $num) : array { @@ -1869,6 +2178,10 @@ class QR extends TwoDAbstract /** * Return new bitstream from bytes + * + * @return array + * + * @since 1.0.0 */ protected function newFromBytes(int $size, array $data) : array { @@ -1891,6 +2204,10 @@ class QR extends TwoDAbstract /** * Append one bitstream to another + * + * @return array + * + * @since 1.0.0 */ protected function appendBitstream(array $bitstream, array $append) : array { @@ -1907,6 +2224,10 @@ class QR extends TwoDAbstract /** * Append one bitstream created from number to another + * + * @return array + * + * @since 1.0.0 */ protected function appendNum(array $bitstream, int $bits, int $num) : array { @@ -1921,6 +2242,10 @@ class QR extends TwoDAbstract /** * Append one bitstream created from bytes to another + * + * @return array + * + * @since 1.0.0 */ protected function appendBytes(array $bitstream, int $size, array $data) : array { @@ -1935,6 +2260,10 @@ class QR extends TwoDAbstract /** * Convert bitstream to bytes + * + * @return array + * + * @since 1.0.0 */ protected function bitstreamToByte(array $bstream) : array { @@ -1976,6 +2305,10 @@ class QR extends TwoDAbstract /** * Replace a value on the array at the specified position + * + * @return array + * + * @since 1.0.0 */ protected function qrstrset(array $srctab, int $x, int $y, string $repl, int $replLen = 0) : array { @@ -1991,6 +2324,10 @@ class QR extends TwoDAbstract /** * Return a version number that satisfies the input code length. + * + * @return int + * + * @since 1.0.0 */ protected function getMinimumVersion(int $size, int $level) : int { @@ -2007,6 +2344,10 @@ class QR extends TwoDAbstract /** * Return the size of length indicator for the mode and version. + * + * @return int + * + * @since 1.0.0 */ protected function lengthIndicator(int $mode, int $version) : int { @@ -2027,6 +2368,10 @@ class QR extends TwoDAbstract /** * Return the maximum length for the mode and version. + * + * @return int + * + * @since 1.0.0 */ protected function maximumWords(int $mode, int $version) : int { @@ -2054,6 +2399,10 @@ class QR extends TwoDAbstract /** * Return an array of ECC specification. + * + * @return array + * + * @since 1.0.0 */ protected function getEccSpec(int $version, int $level, array $spec) : array { @@ -2085,6 +2434,10 @@ class QR extends TwoDAbstract /** * Put an alignment marker. + * + * @return array + * + * @since 1.0.0 */ protected function putAlignmentMarker(array $frame, int $ox, int $oy) : array { @@ -2100,6 +2453,10 @@ class QR extends TwoDAbstract /** * Put an alignment pattern. + * + * @return array + * + * @since 1.0.0 */ protected function putAlignmentPattern(int $version, array $frame, int $width) : array { @@ -2148,6 +2505,10 @@ class QR extends TwoDAbstract /** * Put a finder pattern. + * + * @return array + * + * @since 1.0.0 */ protected function putFinderPattern(array $frame, int $ox, int $oy) : array { @@ -2160,6 +2521,10 @@ class QR extends TwoDAbstract /** * Return a copy of initialized frame. + * + * @return array + * + * @since 1.0.0 */ protected function createFrame(int $version) : array { @@ -2239,6 +2604,10 @@ class QR extends TwoDAbstract /** * Set new frame for the specified version. + * + * @return array + * + * @since 1.0.0 */ protected function newFrame(int $version) : array { @@ -2259,6 +2628,10 @@ class QR extends TwoDAbstract /** * Initialize a Reed-Solomon codec and add it to existing rsitems + * + * @return array + * + * @since 1.0.0 */ protected function init_rs(int $symsize, int $gfpoly, int $fcr, int $prim, int $nroots, int $pad) : array { @@ -2280,6 +2653,10 @@ class QR extends TwoDAbstract /** * modnn + * + * @return int + * + * @since 1.0.0 */ protected function modnn(array $rs, int $x) : int { @@ -2293,6 +2670,10 @@ class QR extends TwoDAbstract /** * Initialize a Reed-Solomon codec and returns an array of values. + * + * @return array + * + * @since 1.0.0 */ protected function init_rs_char(int $symsize, int $gfpoly, int $fcr, int $prim, int $nroots, int $pad) : array { @@ -2381,6 +2762,10 @@ class QR extends TwoDAbstract /** * Encode a Reed-Solomon codec and returns the parity array + * + * @return array + * + * @since 1.0.0 */ protected function encode_rs_char(array $rs, array $data, array $parity) : array { diff --git a/Utils/Barcode/TwoDAbstract.php b/Utils/Barcode/TwoDAbstract.php index df3de5104..fcee72db7 100644 --- a/Utils/Barcode/TwoDAbstract.php +++ b/Utils/Barcode/TwoDAbstract.php @@ -35,7 +35,14 @@ abstract class TwoDAbstract extends CodeAbstract return $this->createImage($codeArray); } - public abstract function generateCodeArray() : array; + /** + * Generate code array + * + * @return array + * + * @since 1.0.0 + */ + abstract public function generateCodeArray() : array; /** * Create barcode image diff --git a/Utils/Parser/Calendar/ICalParser.php b/Utils/Parser/Calendar/ICalParser.php index 2f4f822b0..e98c5f0f1 100644 --- a/Utils/Parser/Calendar/ICalParser.php +++ b/Utils/Parser/Calendar/ICalParser.php @@ -12,6 +12,8 @@ */ declare(strict_types=1); +namespace phpOMS\Utils\Parser\Calendar; + /** * iCal parser. * diff --git a/Utils/Parser/Presentation/PresentationWriter.php b/Utils/Parser/Presentation/PresentationWriter.php index 0f0ff7bba..0ecd1171f 100644 --- a/Utils/Parser/Presentation/PresentationWriter.php +++ b/Utils/Parser/Presentation/PresentationWriter.php @@ -20,11 +20,19 @@ use PhpOffice\PhpPresentation\DocumentLayout; use PhpOffice\PhpPresentation\IOFactory; use PhpOffice\PhpPresentation\PhpPresentation; use PhpOffice\PhpPresentation\Shape\Drawing; +use PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter; +use PhpOffice\PhpPresentation\Shape\Drawing\Base64; +use PhpOffice\PhpPresentation\Shape\Drawing\File; +use PhpOffice\PhpPresentation\Shape\Drawing\Gd; +use PhpOffice\PhpPresentation\Shape\Drawing\ZipFile; use PhpOffice\PhpPresentation\Shape\Group; use PhpOffice\PhpPresentation\Shape\RichText; use PhpOffice\PhpPresentation\Shape\RichText\BreakElement; use PhpOffice\PhpPresentation\Shape\RichText\TextElement; use PhpOffice\PhpPresentation\Slide; +use PhpOffice\PhpPresentation\Slide\AbstractBackground; +use PhpOffice\PhpPresentation\Slide\Background\Color as BackgroundColor; +use PhpOffice\PhpPresentation\Slide\Background\Image; use PhpOffice\PhpPresentation\Style\Alignment; use PhpOffice\PhpPresentation\Style\Bullet; use PhpOffice\PhpPresentation\Style\Color; @@ -122,10 +130,12 @@ class PresentationWriter $this->append('
  • PhpPresentation'); $this->append('
      '); $this->append('
    • Info "PhpPresentation"
    • '); + foreach ($oPHPPpt->getAllSlides() as $oSlide) { $this->append('
    • Slide'); $this->append('
        '); $this->append('
      • Info "Slide"
      • '); + foreach ($oSlide->getShapeCollection() as $oShape) { if ($oShape instanceof Group) { $this->append('
      • Shape "Group"'); @@ -140,9 +150,11 @@ class PresentationWriter $this->displayShape($oShape); } } + $this->append('
      '); $this->append('
    • '); } + $this->append('
    '); $this->append('
  • '); } @@ -158,13 +170,13 @@ class PresentationWriter */ protected function displayShape(AbstractShape $shape) : void { - if ($shape instanceof Drawing\Gd) { + if ($shape instanceof Gd) { $this->append('
  • Shape "Drawing\Gd"
  • '); - } elseif ($shape instanceof Drawing\File) { + } elseif ($shape instanceof File) { $this->append('
  • Shape "Drawing\File"
  • '); - } elseif ($shape instanceof Drawing\Base64) { + } elseif ($shape instanceof Base64) { $this->append('
  • Shape "Drawing\Base64"
  • '); - } elseif ($shape instanceof Drawing\ZipFile) { + } elseif ($shape instanceof ZipFile) { $this->append('
  • Shape "Drawing\Zip"
  • '); } elseif ($shape instanceof RichText) { $this->append('
  • Shape "RichText"
  • '); @@ -214,15 +226,17 @@ class PresentationWriter $this->append('
    Extent X
    ' . $oSlide->getExtentX() . '
    '); $this->append('
    Extent Y
    ' . $oSlide->getExtentY() . '
    '); $oBkg = $oSlide->getBackground(); - if ($oBkg instanceof Slide\AbstractBackground) { - if ($oBkg instanceof Slide\Background\Color) { + + if ($oBkg instanceof AbstractBackground) { + if ($oBkg instanceof BackgroundColor) { $this->append('
    Background Color
    #' . $oBkg->getColor()->getRGB() . '
    '); } - if ($oBkg instanceof Slide\Background\Image) { + if ($oBkg instanceof Image) { $sBkgImgContents = file_get_contents($oBkg->getPath()); - $this->append('
    Background Image
    '); + $this->append('
    Background Image
    '); } } + $oNote = $oSlide->getNote(); if ($oNote->getShapeCollection()->count() > 0) { $this->append('
    Notes
    '); @@ -269,7 +283,8 @@ class PresentationWriter $this->append('
    Rotation
    ' . $oShape->getRotation() . '°
    '); $this->append('
    Hyperlink
    ' . ucfirst(var_export($oShape->hasHyperlink(), true)) . '
    '); $this->append('
    Fill
    '); - if (is_null($oShape->getFill())) { + + if ($oShape->getFill() === null) { $this->append('
    None
    '); } else { switch ($oShape->getFill()->getFillType()) { @@ -284,9 +299,11 @@ class PresentationWriter break; } } + $this->append('
    Border
    @Todo
    '); $this->append('
    IsPlaceholder
    ' . ($oShape->isPlaceholder() ? 'true' : 'false') . '
    '); - if ($oShape instanceof Drawing\Gd) { + + if ($oShape instanceof Gd) { $this->append('
    Name
    ' . $oShape->getName() . '
    '); $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); ob_start(); @@ -294,12 +311,14 @@ class PresentationWriter $sShapeImgContents = ob_get_contents(); ob_end_clean(); $this->append('
    Mime-Type
    ' . $oShape->getMimeType() . '
    '); - $this->append('
    Image
    '); + $this->append('
    Image
    '); + if ($oShape->hasHyperlink()) { $this->append('
    Hyperlink URL
    ' . $oShape->getHyperlink()->getUrl() . '
    '); $this->append('
    Hyperlink Tooltip
    ' . $oShape->getHyperlink()->getTooltip() . '
    '); } - } elseif ($oShape instanceof Drawing\AbstractDrawingAdapter) { + + } elseif ($oShape instanceof AbstractDrawingAdapter) { $this->append('
    Name
    ' . $oShape->getName() . '
    '); $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); } elseif ($oShape instanceof RichText) { @@ -307,6 +326,7 @@ class PresentationWriter $this->append('
    Inset (T / R / B / L)
    ' . $oShape->getInsetTop() . 'px / ' . $oShape->getInsetRight() . 'px / ' . $oShape->getInsetBottom() . 'px / ' . $oShape->getInsetLeft() . 'px
    '); $this->append('
    Text
    '); $this->append('
    '); + foreach ($oShape->getParagraphs() as $oParagraph) { $this->append('Paragraph
    '); $this->append('
    Alignment Horizontal
    Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getHorizontal()) . '
    '); @@ -315,19 +335,24 @@ class PresentationWriter $this->append('
    Alignment Indent
    ' . $oParagraph->getAlignment()->getIndent() . ' px
    '); $this->append('
    Alignment Level
    ' . $oParagraph->getAlignment()->getLevel() . '
    '); $this->append('
    Bullet Style
    Bullet::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $oParagraph->getBulletStyle()->getBulletType()) . '
    '); + if (Bullet::TYPE_NONE != $oParagraph->getBulletStyle()->getBulletType()) { $this->append('
    Bullet Font
    ' . $oParagraph->getBulletStyle()->getBulletFont() . '
    '); $this->append('
    Bullet Color
    ' . $oParagraph->getBulletStyle()->getBulletColor()->getARGB() . '
    '); } + if (Bullet::TYPE_BULLET == $oParagraph->getBulletStyle()->getBulletType()) { $this->append('
    Bullet Char
    ' . $oParagraph->getBulletStyle()->getBulletChar() . '
    '); } + if (Bullet::TYPE_NUMERIC == $oParagraph->getBulletStyle()->getBulletType()) { $this->append('
    Bullet Start At
    ' . $oParagraph->getBulletStyle()->getBulletNumericStartAt() . '
    '); $this->append('
    Bullet Style
    ' . $oParagraph->getBulletStyle()->getBulletNumericStyle() . '
    '); } + $this->append('
    Line Spacing
    ' . $oParagraph->getLineSpacing() . '
    '); $this->append('
    RichText
    '); + foreach ($oParagraph->getRichTextElements() as $oRichText) { if ($oRichText instanceof BreakElement) { $this->append('
    Break
    '); @@ -337,6 +362,7 @@ class PresentationWriter } else { $this->append('
    Run
    '); } + $this->append('
    ' . $oRichText->getText()); $this->append('
    '); $this->append('
    Font Name
    ' . $oRichText->getFont()->getName() . '
    '); @@ -350,22 +376,25 @@ class PresentationWriter $this->append('SubScript : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - '); $this->append('SuperScript : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N')); $this->append('
    '); + if ($oRichText instanceof TextElement) { if ($oRichText->hasHyperlink()) { $this->append('
    Hyperlink URL
    ' . $oRichText->getHyperlink()->getUrl() . '
    '); $this->append('
    Hyperlink Tooltip
    ' . $oRichText->getHyperlink()->getTooltip() . '
    '); } } + $this->append('
    '); $this->append('
    '); } } + $this->append('
    '); } + $this->append(''); - } else { - // Add another shape } + $this->append(''); $this->append(''); } @@ -377,7 +406,7 @@ class PresentationWriter * @param string $search Value to search for * @param string $startWith Constant name it starts with * - * @return void + * @return string * * @since 1.0.0 */ @@ -386,11 +415,13 @@ class PresentationWriter $fooClass = new \ReflectionClass($class); $constants = $fooClass->getConstants(); $constName = ''; + foreach ($constants as $key => $value) { if ($value == $search) { if (empty($startWith) || (!empty($startWith) && \strpos($key, $startWith) === 0)) { $constName = $key; } + break; } } diff --git a/Views/View.php b/Views/View.php index f54ef7eb2..03638df8f 100755 --- a/Views/View.php +++ b/Views/View.php @@ -341,10 +341,9 @@ class View extends ViewAbstract * Print a currency * * @param int|float|Money $currency Currency value to print - * @param int $precision Precision - * @param null|string $symbol Currency name/symbol - * @param null|string $format Format type to use - * @param int $divide Divide currency by divisor + * @param null|string $symbol Currency name/symbol + * @param null|string $format Format type to use + * @param int $divide Divide currency by divisor * * @return string *