diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 850bf7564..14d16799c 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -414,6 +414,7 @@ final class WriteMapper extends DataMapperAbstract // @codeCoverageIgnoreStart \var_dump($e->getMessage()); \var_dump($relQuery->toSql()); + \var_dump(\debug_backtrace()); // @codeCoverageIgnoreEnd } } diff --git a/DataStorage/Session/CacheSessionHandler.php b/DataStorage/Session/CacheSessionHandler.php index 82491bdc0..33f58bcef 100644 --- a/DataStorage/Session/CacheSessionHandler.php +++ b/DataStorage/Session/CacheSessionHandler.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Session; -use phpOMS\DataStorage\Cache\Connection\ConnectionAbstract; use phpOMS\DataStorage\Cache\CacheStatus; +use phpOMS\DataStorage\Cache\Connection\ConnectionAbstract; /** * Cache session handler. @@ -82,11 +82,11 @@ final class CacheSessionHandler implements \SessionHandlerInterface, \SessionIdI */ public function open(string $savePath, string $sessionName) : bool { - if ($con->getStatus() !== CacheStatus::OK) { - $con->connect(); + if ($this->con->getStatus() !== CacheStatus::OK) { + $this->con->connect(); } - return $con->getStatus() === CacheStatus::OK; + return $this->con->getStatus() === CacheStatus::OK; } /** @@ -120,7 +120,7 @@ final class CacheSessionHandler implements \SessionHandlerInterface, \SessionIdI $this->con->updateExpire($this->expire); - return $data; + return (string) $data; } /** @@ -167,6 +167,6 @@ final class CacheSessionHandler implements \SessionHandlerInterface, \SessionIdI */ public function gc(int $maxlifetime) : int|false { - (int) $this->con->flush($maxlifetime); + return (int) $this->con->flush($maxlifetime); } } diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 98ede1efa..2312369cf 100755 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -755,7 +755,9 @@ final class ModuleManager $name = $this->generateModuleName($module); if (!isset($this->running[$class])) { - if (Autoloader::exists($class) !== false) { + if (Autoloader::exists($class) !== false + || Autoloader::exists($class = '\\Modules\\' . $module . '\\Controller\\Controller') !== false + ) { try { /** @var ModuleAbstract $obj */ $obj = new $class($this->app); diff --git a/Router/RouterInterface.php b/Router/RouterInterface.php index 6e5226171..38ff3e52c 100755 --- a/Router/RouterInterface.php +++ b/Router/RouterInterface.php @@ -75,7 +75,7 @@ interface RouterInterface * @param string $csrf CSRF token * @param int $verb Route verb * @param string $app Application name - * @param int $unitId Organization id + * @param int $unitId Organization id * @param Account $account Account * @param array $data Data * diff --git a/Socket/SocketAbstract.php b/Socket/SocketAbstract.php index 114296dd2..26f72050f 100755 --- a/Socket/SocketAbstract.php +++ b/Socket/SocketAbstract.php @@ -51,7 +51,7 @@ abstract class SocketAbstract implements SocketInterface /** * Socket. * - * @var null|resource + * @var null|\Socket * @since 1.0.0 */ protected $sock; diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 129a2f906..dabbb3ebf 100755 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -293,11 +293,11 @@ final class Directory extends FileAbstract implements DirectoryInterface $counter = 0; $files = \scandir($path); - do { - if ($files === false) { - return false; // @codeCoverageIgnore - } + if ($files === false) { + return false; // @codeCoverageIgnore + } + do { foreach ($files as $file) { if ($file === '.' || $file === '..') { continue; @@ -311,9 +311,11 @@ final class Directory extends FileAbstract implements DirectoryInterface } ++$counter; - } while ($counter < 3 && \count($files = \scandir($path)) > 2); + $files = \scandir($path); + } while ($files !== false && $counter < 3 && \count($files) > 2); - if (\count(\scandir($path)) > 2) { + $files = \scandir($path); + if ($files === false || \count($files) > 2) { return false; } diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index 8a9de15e0..e5325022d 100755 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -200,7 +200,9 @@ final class ImageUtils $src2 = \imagecreatefromgif($img2); } - if ($src1 === null || $src2 === null) { + if ($src1 === null || $src2 === null + || $src1 === false || $src2 === false + ) { return 0; } @@ -216,13 +218,25 @@ final class ImageUtils ? \imagecreatetruecolor($newDim[0], $newDim[1]) : \imagecrop($src2, ['x' => 0, 'y' => 0, 'width' => $imageDim2[0], 'height' => $imageDim2[1]]); + if ($dst === false) { + return 0; + } + $alpha = \imagecolorallocatealpha($dst, 255, 255, 255, 127); + if ($alpha === false) { + return 0; + } + if ($diff === 0) { \imagefill($dst, 0, 0, $alpha); } $red = \imagecolorallocate($dst, 255, 0, 0); $green = \imagecolorallocate($dst, 0, 255, 0); + + if ($red === false || $green === false) { + return 0; + } } $difference = 0; @@ -236,7 +250,7 @@ final class ImageUtils if ($i >= $imageDim2[0] || $j >= $imageDim2[1]) { \imagesetpixel($dst, $i, $j, $green); } else { - $color2 = \imagecolerat($src2, $i, $j); + $color2 = \imagecolorat($src2, $i, $j); \imagesetpixel($dst, $i, $j, $color2); } } @@ -252,7 +266,7 @@ final class ImageUtils if ($i >= $imageDim1[0] || $j >= $imageDim1[1]) { \imagesetpixel($dst, $i, $j, $red); } else { - $color1 = \imagecolerat($src1, $i, $j); + $color1 = \imagecolorat($src1, $i, $j); \imagesetpixel($dst, $i, $j, $color1); } } @@ -261,10 +275,10 @@ final class ImageUtils continue; } - $color1 = \imagecolerat($src1, $i, $j); - $color2 = \imagecolerat($src2, $i, $j); + $color1 = \imagecolorat($src1, $i, $j); + $color2 = \imagecolorat($src2, $i, $j); - if ($color1 !== $color2) { + if ($color1 !== $color2 && $color1 !== false && $color2 !== null) { ++$difference; if ($diff === 0) { @@ -288,7 +302,7 @@ final class ImageUtils \imagedestroy($src1); \imagedestroy($src2); - \imagedestroy($dest); + \imagedestroy($dst); } return $difference; diff --git a/Utils/Parser/Document/DocumentWriter.php b/Utils/Parser/Document/DocumentWriter.php index 272493429..7bf0130fe 100644 --- a/Utils/Parser/Document/DocumentWriter.php +++ b/Utils/Parser/Document/DocumentWriter.php @@ -16,6 +16,7 @@ namespace phpOMS\Utils\Parser\Document; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; +use PhpOffice\PhpWord\Writer\PDF\AbstractRenderer; use PhpOffice\PhpWord\Writer\WriterInterface; class DocumentWriter extends AbstractRenderer implements WriterInterface @@ -25,19 +26,19 @@ class DocumentWriter extends AbstractRenderer implements WriterInterface * * @param string $filename Name of the file to save as */ - public function toPdfString($filename = null): void + public function toPdfString($filename = null): string { // PDF settings - $paperSize = strtoupper('A4'); + $paperSize = strtoupper('A4'); $orientation = strtoupper('portrait'); // Create PDF - $pdf = $pdf = new \Mpdf\Mpdf(); + $pdf = new \Mpdf\Mpdf(); $pdf->_setPageSize($paperSize, $orientation); $pdf->addPage($orientation); // Write document properties - $phpWord = $this->getPhpWord(); + $phpWord = $this->getPhpWord(); $docProps = $phpWord->getDocInfo(); $pdf->setTitle($docProps->getTitle()); $pdf->setAuthor($docProps->getCreator()); diff --git a/Utils/Parser/Presentation/PresentationWriter.php b/Utils/Parser/Presentation/PresentationWriter.php index c3f3a203b..8ad288fa3 100644 --- a/Utils/Parser/Presentation/PresentationWriter.php +++ b/Utils/Parser/Presentation/PresentationWriter.php @@ -300,7 +300,7 @@ class PresentationWriter protected function getConstantName($class, $search, $startWith = '') { - $fooClass = new \ReflectionClass($class); + $fooClass = new \ReflectionClass($class); $constants = $fooClass->getConstants(); $constName = null; foreach ($constants as $key => $value) { diff --git a/Utils/Parser/Spreadsheet/SpreadsheetWriter.php b/Utils/Parser/Spreadsheet/SpreadsheetWriter.php index f68582d04..11d65076e 100644 --- a/Utils/Parser/Spreadsheet/SpreadsheetWriter.php +++ b/Utils/Parser/Spreadsheet/SpreadsheetWriter.php @@ -33,20 +33,20 @@ class SpreadsheetWriter extends Pdf $pdf = new \Mpdf\Mpdf(); // Check for paper size and page orientation - $setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup(); - $orientation = $this->getOrientation() ?? $setup->getOrientation(); - $orientation = ($orientation === PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + $setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup(); + $orientation = $this->getOrientation() ?? $setup->getOrientation(); + $orientation = ($orientation === PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->getPaperSize() ?? $setup->getPaperSize(); - $paperSize = self::$paperSizes[$printPaperSize] ?? PageSetup::getPaperSizeDefault(); + $paperSize = self::$paperSizes[$printPaperSize] ?? PageSetup::getPaperSizeDefault(); $ortmp = $orientation; $pdf->_setPageSize($paperSize, $ortmp); $pdf->DefOrientation = $orientation; $pdf->AddPageByArray([ - 'orientation' => $orientation, - 'margin-left' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getLeft()), - 'margin-right' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getRight()), - 'margin-top' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getTop()), + 'orientation' => $orientation, + 'margin-left' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getLeft()), + 'margin-right' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getRight()), + 'margin-top' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getTop()), 'margin-bottom' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getBottom()), ]); @@ -57,8 +57,9 @@ class SpreadsheetWriter extends Pdf $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); - $html = $this->generateHTMLAll(); + $html = $this->generateHTMLAll(); $bodyLocation = strpos($html, Html::BODY_LINE); + // Make sure first data presented to Mpdf includes body tag // so that Mpdf doesn't parse it as content. Issue 2432. if ($bodyLocation !== false) { @@ -66,6 +67,7 @@ class SpreadsheetWriter extends Pdf $pdf->WriteHTML(substr($html, 0, $bodyLocation)); $html = substr($html, $bodyLocation); } + foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) { $pdf->WriteHTML(\implode(PHP_EOL, $lines)); } diff --git a/tests/Application/ApplicationManagerTest.php b/tests/Application/ApplicationManagerTest.php index 66a96d614..85d68e3a2 100755 --- a/tests/Application/ApplicationManagerTest.php +++ b/tests/Application/ApplicationManagerTest.php @@ -20,11 +20,11 @@ use phpOMS\Application\ApplicationAbstract; use phpOMS\Application\ApplicationManager; use phpOMS\Config\OptionsTrait; use phpOMS\Config\SettingsInterface; +use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; use phpOMS\Dispatcher\Dispatcher; use phpOMS\Module\ModuleManager; use phpOMS\Router\WebRouter; use phpOMS\System\File\Local\Directory; -use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; /** * @testdox phpOMS\tests\Application\ApplicationManagerTest: Application manager @@ -63,6 +63,7 @@ final class ApplicationManagerTest extends \PHPUnit\Framework\TestCase public function get( mixed $ids = null, string | array $names = null, + int $unit = null, int $app = null, string $module = null, int $group = null, diff --git a/tests/DataStorage/Database/TestModel/BaseModelMapper.php b/tests/DataStorage/Database/TestModel/BaseModelMapper.php index 1e3edb20c..68fcb7903 100755 --- a/tests/DataStorage/Database/TestModel/BaseModelMapper.php +++ b/tests/DataStorage/Database/TestModel/BaseModelMapper.php @@ -43,7 +43,7 @@ class BaseModelMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -63,7 +63,7 @@ class BaseModelMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/tests/Module/InstallerAbstractTest.php b/tests/Module/InstallerAbstractTest.php index 49cde49ca..6d72234fd 100755 --- a/tests/Module/InstallerAbstractTest.php +++ b/tests/Module/InstallerAbstractTest.php @@ -39,8 +39,6 @@ final class InstallerAbstractTest extends \PHPUnit\Framework\TestCase $this->installer = new class() extends InstallerAbstract { }; - - $this->installer->dbPool = $GLOBALS['dbpool']; } /** @@ -63,6 +61,7 @@ final class InstallerAbstractTest extends \PHPUnit\Framework\TestCase public function get( mixed $ids = null, string | array $names = null, + int $unit = null, int $app = null, string $module = null, int $group = null,