phpstan, phpcs, phpunit fixes

This commit is contained in:
Dennis Eichhorn 2023-01-27 22:12:09 +01:00
parent 9cb5138201
commit df4611731f
13 changed files with 63 additions and 41 deletions

View File

@ -414,6 +414,7 @@ final class WriteMapper extends DataMapperAbstract
// @codeCoverageIgnoreStart
\var_dump($e->getMessage());
\var_dump($relQuery->toSql());
\var_dump(\debug_backtrace());
// @codeCoverageIgnoreEnd
}
}

View File

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

View File

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

View File

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

View File

@ -51,7 +51,7 @@ abstract class SocketAbstract implements SocketInterface
/**
* Socket.
*
* @var null|resource
* @var null|\Socket
* @since 1.0.0
*/
protected $sock;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ class BaseModelMapper extends DataMapperFactory
/**
* Belongs to.
*
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}>
* @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
* @since 1.0.0
*/
public const BELONGS_TO = [
@ -63,7 +63,7 @@ class BaseModelMapper extends DataMapperFactory
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [

View File

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