fix static analysis

This commit is contained in:
Dennis Eichhorn 2023-04-09 06:03:39 +02:00
parent b9cc466bed
commit 859a04c791
34 changed files with 867 additions and 132 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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;
}

View File

@ -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 = [

View File

@ -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

View File

@ -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:

View File

@ -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
*

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -1,5 +1,13 @@
<?php
class SARIMA {
}
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -40,25 +40,38 @@ final class Forecasts
return [$forecast - $interval * $standardDeviation, $forecast + $interval * $standardDeviation];
}
/**
* Simple seasonal forecast.
*
* @param array<int|float> $history History
* @param int $periods Number of periods to forecast
* @param int $seasonality Seasonality
*
* @return array<int|float>
*
* @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;

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -0,0 +1,13 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Math\Statistic\Forecast
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);

View File

@ -1133,5 +1133,4 @@ final class HttpHeader extends HeaderAbstract
$this->set('Status', 'Status: HTTP/1.0 599 Network connect timeout error');
\http_response_code(599);
}
}

View File

@ -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

View File

@ -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] ?? [];

View File

@ -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
*

View File

@ -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;
}

View File

@ -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
*/

View File

@ -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;
}

View File

@ -391,7 +391,16 @@ class Directory extends FileAbstract implements DirectoryInterface
continue;
}
$e = [];
$e = [
'permission' => '',
'number' => '',
'user' => '',
'group' => '',
'size' => '',
'month' => '',
'day' => '',
'time' => '',
];
list(
$e['permission'],

View File

@ -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

View File

@ -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];

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -12,6 +12,8 @@
*/
declare(strict_types=1);
namespace phpOMS\Utils\Parser\Calendar;
/**
* iCal parser.
*

View File

@ -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('<li><span><i class="fa fa-folder-open"></i> PhpPresentation</span>');
$this->append('<ul>');
$this->append('<li><span class="shape" id="divPhpPresentation"><i class="fa fa-info-circle"></i> Info "PhpPresentation"</span></li>');
foreach ($oPHPPpt->getAllSlides() as $oSlide) {
$this->append('<li><span><i class="fa fa-minus-square"></i> Slide</span>');
$this->append('<ul>');
$this->append('<li><span class="shape" id="div' . $oSlide->getHashCode() . '"><i class="fa fa-info-circle"></i> Info "Slide"</span></li>');
foreach ($oSlide->getShapeCollection() as $oShape) {
if ($oShape instanceof Group) {
$this->append('<li><span><i class="fa fa-minus-square"></i> Shape "Group"</span>');
@ -140,9 +150,11 @@ class PresentationWriter
$this->displayShape($oShape);
}
}
$this->append('</ul>');
$this->append('</li>');
}
$this->append('</ul>');
$this->append('</li>');
}
@ -158,13 +170,13 @@ class PresentationWriter
*/
protected function displayShape(AbstractShape $shape) : void
{
if ($shape instanceof Drawing\Gd) {
if ($shape instanceof Gd) {
$this->append('<li><span class="shape" id="div' . $shape->getHashCode() . '">Shape "Drawing\Gd"</span></li>');
} elseif ($shape instanceof Drawing\File) {
} elseif ($shape instanceof File) {
$this->append('<li><span class="shape" id="div' . $shape->getHashCode() . '">Shape "Drawing\File"</span></li>');
} elseif ($shape instanceof Drawing\Base64) {
} elseif ($shape instanceof Base64) {
$this->append('<li><span class="shape" id="div' . $shape->getHashCode() . '">Shape "Drawing\Base64"</span></li>');
} elseif ($shape instanceof Drawing\ZipFile) {
} elseif ($shape instanceof ZipFile) {
$this->append('<li><span class="shape" id="div' . $shape->getHashCode() . '">Shape "Drawing\Zip"</span></li>');
} elseif ($shape instanceof RichText) {
$this->append('<li><span class="shape" id="div' . $shape->getHashCode() . '">Shape "RichText"</span></li>');
@ -214,15 +226,17 @@ class PresentationWriter
$this->append('<dt>Extent X</dt><dd>' . $oSlide->getExtentX() . '</dd>');
$this->append('<dt>Extent Y</dt><dd>' . $oSlide->getExtentY() . '</dd>');
$oBkg = $oSlide->getBackground();
if ($oBkg instanceof Slide\AbstractBackground) {
if ($oBkg instanceof Slide\Background\Color) {
if ($oBkg instanceof AbstractBackground) {
if ($oBkg instanceof BackgroundColor) {
$this->append('<dt>Background Color</dt><dd>#' . $oBkg->getColor()->getRGB() . '</dd>');
}
if ($oBkg instanceof Slide\Background\Image) {
if ($oBkg instanceof Image) {
$sBkgImgContents = file_get_contents($oBkg->getPath());
$this->append('<dt>Background Image</dt><dd><img src="data:image/png;base64,' . base64_encode($sBkgImgContents) . '"></dd>');
$this->append('<dt>Background Image</dt><dd><img src="data:image/png;base64,' . \base64_encode($sBkgImgContents) . '"></dd>');
}
}
$oNote = $oSlide->getNote();
if ($oNote->getShapeCollection()->count() > 0) {
$this->append('<dt>Notes</dt>');
@ -269,7 +283,8 @@ class PresentationWriter
$this->append('<dt>Rotation</dt><dd>' . $oShape->getRotation() . '°</dd>');
$this->append('<dt>Hyperlink</dt><dd>' . ucfirst(var_export($oShape->hasHyperlink(), true)) . '</dd>');
$this->append('<dt>Fill</dt>');
if (is_null($oShape->getFill())) {
if ($oShape->getFill() === null) {
$this->append('<dd>None</dd>');
} else {
switch ($oShape->getFill()->getFillType()) {
@ -284,9 +299,11 @@ class PresentationWriter
break;
}
}
$this->append('<dt>Border</dt><dd>@Todo</dd>');
$this->append('<dt>IsPlaceholder</dt><dd>' . ($oShape->isPlaceholder() ? 'true' : 'false') . '</dd>');
if ($oShape instanceof Drawing\Gd) {
if ($oShape instanceof Gd) {
$this->append('<dt>Name</dt><dd>' . $oShape->getName() . '</dd>');
$this->append('<dt>Description</dt><dd>' . $oShape->getDescription() . '</dd>');
ob_start();
@ -294,12 +311,14 @@ class PresentationWriter
$sShapeImgContents = ob_get_contents();
ob_end_clean();
$this->append('<dt>Mime-Type</dt><dd>' . $oShape->getMimeType() . '</dd>');
$this->append('<dt>Image</dt><dd><img src="data:' . $oShape->getMimeType() . ';base64,' . base64_encode($sShapeImgContents) . '"></dd>');
$this->append('<dt>Image</dt><dd><img src="data:' . $oShape->getMimeType() . ';base64,' . \base64_encode($sShapeImgContents) . '"></dd>');
if ($oShape->hasHyperlink()) {
$this->append('<dt>Hyperlink URL</dt><dd>' . $oShape->getHyperlink()->getUrl() . '</dd>');
$this->append('<dt>Hyperlink Tooltip</dt><dd>' . $oShape->getHyperlink()->getTooltip() . '</dd>');
}
} elseif ($oShape instanceof Drawing\AbstractDrawingAdapter) {
} elseif ($oShape instanceof AbstractDrawingAdapter) {
$this->append('<dt>Name</dt><dd>' . $oShape->getName() . '</dd>');
$this->append('<dt>Description</dt><dd>' . $oShape->getDescription() . '</dd>');
} elseif ($oShape instanceof RichText) {
@ -307,6 +326,7 @@ class PresentationWriter
$this->append('<dt>Inset (T / R / B / L)</dt><dd>' . $oShape->getInsetTop() . 'px / ' . $oShape->getInsetRight() . 'px / ' . $oShape->getInsetBottom() . 'px / ' . $oShape->getInsetLeft() . 'px</dd>');
$this->append('<dt>Text</dt>');
$this->append('<dd>');
foreach ($oShape->getParagraphs() as $oParagraph) {
$this->append('Paragraph<dl>');
$this->append('<dt>Alignment Horizontal</dt><dd> Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getHorizontal()) . '</dd>');
@ -315,19 +335,24 @@ class PresentationWriter
$this->append('<dt>Alignment Indent</dt><dd>' . $oParagraph->getAlignment()->getIndent() . ' px</dd>');
$this->append('<dt>Alignment Level</dt><dd>' . $oParagraph->getAlignment()->getLevel() . '</dd>');
$this->append('<dt>Bullet Style</dt><dd> Bullet::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $oParagraph->getBulletStyle()->getBulletType()) . '</dd>');
if (Bullet::TYPE_NONE != $oParagraph->getBulletStyle()->getBulletType()) {
$this->append('<dt>Bullet Font</dt><dd>' . $oParagraph->getBulletStyle()->getBulletFont() . '</dd>');
$this->append('<dt>Bullet Color</dt><dd>' . $oParagraph->getBulletStyle()->getBulletColor()->getARGB() . '</dd>');
}
if (Bullet::TYPE_BULLET == $oParagraph->getBulletStyle()->getBulletType()) {
$this->append('<dt>Bullet Char</dt><dd>' . $oParagraph->getBulletStyle()->getBulletChar() . '</dd>');
}
if (Bullet::TYPE_NUMERIC == $oParagraph->getBulletStyle()->getBulletType()) {
$this->append('<dt>Bullet Start At</dt><dd>' . $oParagraph->getBulletStyle()->getBulletNumericStartAt() . '</dd>');
$this->append('<dt>Bullet Style</dt><dd>' . $oParagraph->getBulletStyle()->getBulletNumericStyle() . '</dd>');
}
$this->append('<dt>Line Spacing</dt><dd>' . $oParagraph->getLineSpacing() . '</dd>');
$this->append('<dt>RichText</dt><dd><dl>');
foreach ($oParagraph->getRichTextElements() as $oRichText) {
if ($oRichText instanceof BreakElement) {
$this->append('<dt><i>Break</i></dt>');
@ -337,6 +362,7 @@ class PresentationWriter
} else {
$this->append('<dt><i>Run</i></dt>');
}
$this->append('<dd>' . $oRichText->getText());
$this->append('<dl>');
$this->append('<dt>Font Name</dt><dd>' . $oRichText->getFont()->getName() . '</dd>');
@ -350,22 +376,25 @@ class PresentationWriter
$this->append('<abbr title="SubScript">SubScript</abbr> : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - ');
$this->append('<abbr title="SuperScript">SuperScript</abbr> : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N'));
$this->append('</dd>');
if ($oRichText instanceof TextElement) {
if ($oRichText->hasHyperlink()) {
$this->append('<dt>Hyperlink URL</dt><dd>' . $oRichText->getHyperlink()->getUrl() . '</dd>');
$this->append('<dt>Hyperlink Tooltip</dt><dd>' . $oRichText->getHyperlink()->getTooltip() . '</dd>');
}
}
$this->append('</dl>');
$this->append('</dd>');
}
}
$this->append('</dl></dd></dl>');
}
$this->append('</dd>');
} else {
// Add another shape
}
$this->append('</dl>');
$this->append('</div>');
}
@ -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;
}
}

View File

@ -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
*