fix: phpstan level=6

This commit is contained in:
origami11@yandex.ru 2025-10-06 12:49:36 +03:00
parent acbf2c847d
commit 48269bd424
41 changed files with 324 additions and 347 deletions

View file

@ -8,8 +8,8 @@ use ctiso\Tools\Drawing;
class TemplateImage
{
static $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp');
static $listfonts = array(
static array $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp');
static array $listfonts = array(
'georgia' => 'georgia.ttf',
'georgiabd' => 'georgiab.ttf',
'georgiaz' => 'georgiaz.ttf',
@ -32,16 +32,16 @@ class TemplateImage
);
protected $src;
protected $context = array();
protected $data = array();
protected $base = "c:\\windows\\fonts\\";
protected array $context = [];
protected array $data = [];
protected string $base = "c:\\windows\\fonts\\";
protected $image;
protected $_prepare = true;
public $debug = false;
public $resource;
public $filename;
function __construct (?string $template = null)
function __construct (?array $template = null)
{
if ($template) {
$this->data = $template;
@ -51,7 +51,7 @@ class TemplateImage
/**
* Путь к изображению
*/
function resourcePath(string $path)
function resourcePath(string $path): void
{
$this->resource = $path;
}
@ -59,7 +59,7 @@ class TemplateImage
/**
* Путь у шрифтам
*/
function fontPath(string $path)
function fontPath(string $path): void
{
$this->base = $path;
}
@ -69,13 +69,13 @@ class TemplateImage
$this->context['['.$name.']'] = $this->encode($value);
}
function setImage($name)
function setImage($name): void
{
$this->filename = $name;
$this->image = $this->imagefromfile($name);
}
function setEmptyImage($width, $height)
function setEmptyImage($width, $height): void
{
$this->image = imagecreatetruecolor($width, $height);
}
@ -92,7 +92,7 @@ class TemplateImage
return null;
}
function getFontFile(string $name)
function getFontFile(string $name): string
{
if(array_key_exists(strtolower($name), self::$listfonts)) {
return $this->base . self::$listfonts[$name];
@ -100,7 +100,7 @@ class TemplateImage
return $this->base . 'arial.ttf';
}
function fontSuffix(array $style)
function fontSuffix(array $style): string
{
if($style[0] && $style[1]) return "z";
@ -110,14 +110,8 @@ class TemplateImage
return "";
}
/**
* @param string $text
* @param object $value
*/
function imageText($text, $value)
function imageText(string $text, object $value)
{
assert(is_string($text));
$text = strtr($text, $this->context);
$size = $value->fontSize;
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
@ -148,17 +142,12 @@ class TemplateImage
* Перекодировка текста
* @deprecated
*/
function encode($text)
function encode(string $text): string
{
assert(is_string($text));
return $text; //iconv("WINDOWS-1251", "UTF-8", $text);
}
/**
* @param int $new_width
* @param int $new_height
*/
function setSize($new_width, $new_height)
function setSize(int $new_width, int $new_height): void
{
$width = imagesx($this->image);
$height = imagesy($this->image);
@ -173,7 +162,7 @@ class TemplateImage
$this->image = $image_p;
}
function prepare() {
function prepare(): void {
if($this->_prepare) {
$this->_prepare = false;
foreach ($this->data as $value) {
@ -185,10 +174,8 @@ class TemplateImage
/**
* Генерирует изображение из шаблона
*/
function render($file = null)
function render(?string $file = null): string|bool
{
assert(is_string($file) || is_null($file));
$this->prepare();
if ($file == null) {