mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-14 23:48:40 +00:00
phpstan, phpcs, phpunit fixes
This commit is contained in:
parent
9cb5138201
commit
df4611731f
|
|
@ -414,6 +414,7 @@ final class WriteMapper extends DataMapperAbstract
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
\var_dump($e->getMessage());
|
\var_dump($e->getMessage());
|
||||||
\var_dump($relQuery->toSql());
|
\var_dump($relQuery->toSql());
|
||||||
|
\var_dump(\debug_backtrace());
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\DataStorage\Session;
|
namespace phpOMS\DataStorage\Session;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Cache\Connection\ConnectionAbstract;
|
|
||||||
use phpOMS\DataStorage\Cache\CacheStatus;
|
use phpOMS\DataStorage\Cache\CacheStatus;
|
||||||
|
use phpOMS\DataStorage\Cache\Connection\ConnectionAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache session handler.
|
* Cache session handler.
|
||||||
|
|
@ -82,11 +82,11 @@ final class CacheSessionHandler implements \SessionHandlerInterface, \SessionIdI
|
||||||
*/
|
*/
|
||||||
public function open(string $savePath, string $sessionName) : bool
|
public function open(string $savePath, string $sessionName) : bool
|
||||||
{
|
{
|
||||||
if ($con->getStatus() !== CacheStatus::OK) {
|
if ($this->con->getStatus() !== CacheStatus::OK) {
|
||||||
$con->connect();
|
$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);
|
$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
|
public function gc(int $maxlifetime) : int|false
|
||||||
{
|
{
|
||||||
(int) $this->con->flush($maxlifetime);
|
return (int) $this->con->flush($maxlifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -755,7 +755,9 @@ final class ModuleManager
|
||||||
$name = $this->generateModuleName($module);
|
$name = $this->generateModuleName($module);
|
||||||
|
|
||||||
if (!isset($this->running[$class])) {
|
if (!isset($this->running[$class])) {
|
||||||
if (Autoloader::exists($class) !== false) {
|
if (Autoloader::exists($class) !== false
|
||||||
|
|| Autoloader::exists($class = '\\Modules\\' . $module . '\\Controller\\Controller') !== false
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
/** @var ModuleAbstract $obj */
|
/** @var ModuleAbstract $obj */
|
||||||
$obj = new $class($this->app);
|
$obj = new $class($this->app);
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ abstract class SocketAbstract implements SocketInterface
|
||||||
/**
|
/**
|
||||||
* Socket.
|
* Socket.
|
||||||
*
|
*
|
||||||
* @var null|resource
|
* @var null|\Socket
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $sock;
|
protected $sock;
|
||||||
|
|
|
||||||
|
|
@ -293,11 +293,11 @@ final class Directory extends FileAbstract implements DirectoryInterface
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
$files = \scandir($path);
|
$files = \scandir($path);
|
||||||
|
|
||||||
do {
|
|
||||||
if ($files === false) {
|
if ($files === false) {
|
||||||
return false; // @codeCoverageIgnore
|
return false; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if ($file === '.' || $file === '..') {
|
if ($file === '.' || $file === '..') {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -311,9 +311,11 @@ final class Directory extends FileAbstract implements DirectoryInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
++$counter;
|
++$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,9 @@ final class ImageUtils
|
||||||
$src2 = \imagecreatefromgif($img2);
|
$src2 = \imagecreatefromgif($img2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($src1 === null || $src2 === null) {
|
if ($src1 === null || $src2 === null
|
||||||
|
|| $src1 === false || $src2 === false
|
||||||
|
) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,13 +218,25 @@ final class ImageUtils
|
||||||
? \imagecreatetruecolor($newDim[0], $newDim[1])
|
? \imagecreatetruecolor($newDim[0], $newDim[1])
|
||||||
: \imagecrop($src2, ['x' => 0, 'y' => 0, 'width' => $imageDim2[0], 'height' => $imageDim2[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);
|
$alpha = \imagecolorallocatealpha($dst, 255, 255, 255, 127);
|
||||||
|
if ($alpha === false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($diff === 0) {
|
if ($diff === 0) {
|
||||||
\imagefill($dst, 0, 0, $alpha);
|
\imagefill($dst, 0, 0, $alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
$red = \imagecolorallocate($dst, 255, 0, 0);
|
$red = \imagecolorallocate($dst, 255, 0, 0);
|
||||||
$green = \imagecolorallocate($dst, 0, 255, 0);
|
$green = \imagecolorallocate($dst, 0, 255, 0);
|
||||||
|
|
||||||
|
if ($red === false || $green === false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$difference = 0;
|
$difference = 0;
|
||||||
|
|
@ -236,7 +250,7 @@ final class ImageUtils
|
||||||
if ($i >= $imageDim2[0] || $j >= $imageDim2[1]) {
|
if ($i >= $imageDim2[0] || $j >= $imageDim2[1]) {
|
||||||
\imagesetpixel($dst, $i, $j, $green);
|
\imagesetpixel($dst, $i, $j, $green);
|
||||||
} else {
|
} else {
|
||||||
$color2 = \imagecolerat($src2, $i, $j);
|
$color2 = \imagecolorat($src2, $i, $j);
|
||||||
\imagesetpixel($dst, $i, $j, $color2);
|
\imagesetpixel($dst, $i, $j, $color2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +266,7 @@ final class ImageUtils
|
||||||
if ($i >= $imageDim1[0] || $j >= $imageDim1[1]) {
|
if ($i >= $imageDim1[0] || $j >= $imageDim1[1]) {
|
||||||
\imagesetpixel($dst, $i, $j, $red);
|
\imagesetpixel($dst, $i, $j, $red);
|
||||||
} else {
|
} else {
|
||||||
$color1 = \imagecolerat($src1, $i, $j);
|
$color1 = \imagecolorat($src1, $i, $j);
|
||||||
\imagesetpixel($dst, $i, $j, $color1);
|
\imagesetpixel($dst, $i, $j, $color1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -261,10 +275,10 @@ final class ImageUtils
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$color1 = \imagecolerat($src1, $i, $j);
|
$color1 = \imagecolorat($src1, $i, $j);
|
||||||
$color2 = \imagecolerat($src2, $i, $j);
|
$color2 = \imagecolorat($src2, $i, $j);
|
||||||
|
|
||||||
if ($color1 !== $color2) {
|
if ($color1 !== $color2 && $color1 !== false && $color2 !== null) {
|
||||||
++$difference;
|
++$difference;
|
||||||
|
|
||||||
if ($diff === 0) {
|
if ($diff === 0) {
|
||||||
|
|
@ -288,7 +302,7 @@ final class ImageUtils
|
||||||
|
|
||||||
\imagedestroy($src1);
|
\imagedestroy($src1);
|
||||||
\imagedestroy($src2);
|
\imagedestroy($src2);
|
||||||
\imagedestroy($dest);
|
\imagedestroy($dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $difference;
|
return $difference;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace phpOMS\Utils\Parser\Document;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Settings;
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
use PhpOffice\PhpWord\Writer\PDF\AbstractRenderer;
|
||||||
use PhpOffice\PhpWord\Writer\WriterInterface;
|
use PhpOffice\PhpWord\Writer\WriterInterface;
|
||||||
|
|
||||||
class DocumentWriter extends AbstractRenderer implements WriterInterface
|
class DocumentWriter extends AbstractRenderer implements WriterInterface
|
||||||
|
|
@ -25,14 +26,14 @@ class DocumentWriter extends AbstractRenderer implements WriterInterface
|
||||||
*
|
*
|
||||||
* @param string $filename Name of the file to save as
|
* @param string $filename Name of the file to save as
|
||||||
*/
|
*/
|
||||||
public function toPdfString($filename = null): void
|
public function toPdfString($filename = null): string
|
||||||
{
|
{
|
||||||
// PDF settings
|
// PDF settings
|
||||||
$paperSize = strtoupper('A4');
|
$paperSize = strtoupper('A4');
|
||||||
$orientation = strtoupper('portrait');
|
$orientation = strtoupper('portrait');
|
||||||
|
|
||||||
// Create PDF
|
// Create PDF
|
||||||
$pdf = $pdf = new \Mpdf\Mpdf();
|
$pdf = new \Mpdf\Mpdf();
|
||||||
$pdf->_setPageSize($paperSize, $orientation);
|
$pdf->_setPageSize($paperSize, $orientation);
|
||||||
$pdf->addPage($orientation);
|
$pdf->addPage($orientation);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ class SpreadsheetWriter extends Pdf
|
||||||
|
|
||||||
$html = $this->generateHTMLAll();
|
$html = $this->generateHTMLAll();
|
||||||
$bodyLocation = strpos($html, Html::BODY_LINE);
|
$bodyLocation = strpos($html, Html::BODY_LINE);
|
||||||
|
|
||||||
// Make sure first data presented to Mpdf includes body tag
|
// Make sure first data presented to Mpdf includes body tag
|
||||||
// so that Mpdf doesn't parse it as content. Issue 2432.
|
// so that Mpdf doesn't parse it as content. Issue 2432.
|
||||||
if ($bodyLocation !== false) {
|
if ($bodyLocation !== false) {
|
||||||
|
|
@ -66,6 +67,7 @@ class SpreadsheetWriter extends Pdf
|
||||||
$pdf->WriteHTML(substr($html, 0, $bodyLocation));
|
$pdf->WriteHTML(substr($html, 0, $bodyLocation));
|
||||||
$html = substr($html, $bodyLocation);
|
$html = substr($html, $bodyLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) {
|
foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) {
|
||||||
$pdf->WriteHTML(\implode(PHP_EOL, $lines));
|
$pdf->WriteHTML(\implode(PHP_EOL, $lines));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ use phpOMS\Application\ApplicationAbstract;
|
||||||
use phpOMS\Application\ApplicationManager;
|
use phpOMS\Application\ApplicationManager;
|
||||||
use phpOMS\Config\OptionsTrait;
|
use phpOMS\Config\OptionsTrait;
|
||||||
use phpOMS\Config\SettingsInterface;
|
use phpOMS\Config\SettingsInterface;
|
||||||
|
use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
|
||||||
use phpOMS\Dispatcher\Dispatcher;
|
use phpOMS\Dispatcher\Dispatcher;
|
||||||
use phpOMS\Module\ModuleManager;
|
use phpOMS\Module\ModuleManager;
|
||||||
use phpOMS\Router\WebRouter;
|
use phpOMS\Router\WebRouter;
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox phpOMS\tests\Application\ApplicationManagerTest: Application manager
|
* @testdox phpOMS\tests\Application\ApplicationManagerTest: Application manager
|
||||||
|
|
@ -63,6 +63,7 @@ final class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
public function get(
|
public function get(
|
||||||
mixed $ids = null,
|
mixed $ids = null,
|
||||||
string | array $names = null,
|
string | array $names = null,
|
||||||
|
int $unit = null,
|
||||||
int $app = null,
|
int $app = null,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
int $group = null,
|
int $group = null,
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class BaseModelMapper extends DataMapperFactory
|
||||||
/**
|
/**
|
||||||
* Belongs to.
|
* 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
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const BELONGS_TO = [
|
public const BELONGS_TO = [
|
||||||
|
|
@ -63,7 +63,7 @@ class BaseModelMapper extends DataMapperFactory
|
||||||
/**
|
/**
|
||||||
* Has many relation.
|
* 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
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const HAS_MANY = [
|
public const HAS_MANY = [
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,6 @@ final class InstallerAbstractTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->installer = new class() extends InstallerAbstract
|
$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(
|
public function get(
|
||||||
mixed $ids = null,
|
mixed $ids = null,
|
||||||
string | array $names = null,
|
string | array $names = null,
|
||||||
|
int $unit = null,
|
||||||
int $app = null,
|
int $app = null,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
int $group = null,
|
int $group = null,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user