Skip to content

Commit

Permalink
chore: Add typed properties
Browse files Browse the repository at this point in the history
As discussed/requested in meyfa#215, PHP 7.3 is dropped,  and typed properties shoud be added where possible.
  • Loading branch information
Niellles committed Feb 14, 2024
1 parent 512bf8a commit be62519
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Fonts/FontRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class FontRegistry
{
private $fontFiles = [];
private array $fontFiles = [];

public function addFont(string $filePath): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Fonts/TrueTypeFontFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class TrueTypeFontFile extends FontFile
private const PLATFORM_ID_MACINTOSH = 1;
private const PLATFORM_ID_WINDOWS = 3;

private $family;
private $subfamily;
private $weightClass;
private string $family;
private string $subfamily;
private ?int $weightClass;

public function __construct(string $path, string $family, string $subfamily, ?int $weightClass)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Nodes/SVGNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
abstract class SVGNode
{
/** @var SVGNodeContainer $parent The parent node. */
protected $parent;
protected SVGNodeContainer $parent;
/** @var string[] $namespaces A map of custom namespaces to their URIs. */
private $namespaces;
/** @var string[] $attributes This node's set of attributes. */
protected $attributes;
protected array $attributes;
/** @var string[] $styles This node's set of explicit style declarations. */
protected $styles;
protected array $styles;
/** @var string $value This node's value */
protected $value;
protected string $value;

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nodes/Structures/SVGDocumentFragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SVGDocumentFragment extends SVGNodeContainer
const TAG_NAME = 'svg';

/** @var array $initialStyles A map of style keys to their defaults. */
private static $initialStyles = [
private static array $initialStyles = [
'fill' => '#000000',
'stroke' => 'none',
'stroke-width' => '1',
Expand Down
14 changes: 7 additions & 7 deletions src/Rasterization/Path/PathApproximator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PathApproximator
/**
* @var string[] $commands A map of command ids to approximation functions.
*/
private static $commands = [
private static array $commands = [
'M' => 'moveTo', 'm' => 'moveTo',
'L' => 'lineTo', 'l' => 'lineTo',
'H' => 'lineToHorizontal', 'h' => 'lineToHorizontal',
Expand All @@ -35,7 +35,7 @@ class PathApproximator
/**
* @var BezierApproximator $bezier The singleton bezier approximator.
*/
private static $bezier;
private static BezierApproximator $bezier;
/**
* @var ArcApproximator $arc The singleton arc approximator.
*/
Expand All @@ -44,17 +44,17 @@ class PathApproximator
/**
* @var Transform $transform The transform to use.
*/
private $transform;
private Transform $transform;

/**
* @var float[][][] $subpaths The approximation result up until now.
*/
private $subpaths = [];
private array $subpaths = [];

/**
* @var PolygonBuilder|null $builder The current subpath builder.
*/
private $builder;
private ?PolygonBuilder $builder;

// the start of the current subpath, in path coordinates
private $firstX;
Expand All @@ -71,11 +71,11 @@ class PathApproximator
/**
* @var float[] $cubicOld Second control point of last C or S command.
*/
private $cubicOld;
private array $cubicOld;
/**
* @var float[] $quadraticOld Control point of last Q or T command.
*/
private $quadraticOld;
private array $quadraticOld;

/**
* Construct a new, empty approximator.
Expand Down
2 changes: 1 addition & 1 deletion src/Rasterization/Path/PathParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PathParser
/**
* @var int[] $commandLengths A map of command ids to their argument counts.
*/
private static $commandLengths = [
private static array $commandLengths = [
'M' => 2, 'm' => 2, // MoveTo
'L' => 2, 'l' => 2, // LineTo
'H' => 1, 'h' => 1, // LineToHorizontal
Expand Down
6 changes: 3 additions & 3 deletions src/Rasterization/Path/PolygonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class PolygonBuilder
/**
* @var array[] $points The polygon being built (array of float 2-tuples).
*/
private $points = [];
private array $points = [];

/**
* @var float $posX The current x position.
*/
private $posX;
private float $posX;
/**
* @var float $posY The current y position.
*/
private $posY;
private float $posY;

/**
* @param float $posX The starting x position.
Expand Down
6 changes: 3 additions & 3 deletions src/Rasterization/Renderers/PathRendererEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ class PathRendererEdge
/**
* @var int The vertical winding direction of this edge, 1 if top to bottom, -1 if bottom to top.
*/
public $direction;
public int $direction;

/**
* @var float Delta x over delta y of this edge, or 0 if the edge is fully horizontal (dy === 0).
*/
public $inverseSlope;
public float $inverseSlope;

/**
* @var float Initially, the x coordinate belonging to the maxY value, but slides upwards during scanning.
*/
public $x;
public float $x;

/**
* Construct a new edge object from the two end points. The order of points is important here,
Expand Down
14 changes: 7 additions & 7 deletions src/Rasterization/SVGRasterizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ class SVGRasterizer
/** @var Renderers\Renderer[] $renderers Map of shapes to renderers. */
private static $renderers;

private $fontRegistry;
private ?FontRegistry $fontRegistry;

/**
* @var float[] The document's viewBox (x, y, w, h).
*/
private $viewBox;
private ?array $viewBox;

/**
* @var int $width The output image width, in pixels.
*/
private $width;
private int $width;
/**
* @var int $height The output image height, in pixels.
*/
private $height;
private int $height;

/** @var resource $outImage The output image as a GD resource. */
private $outImage;

// precomputed properties for getter methods, used often during render
private $docWidth;
private $docHeight;
private ?float $docWidth;
private ?float $docHeight;
private $diagonalScale;

private $transformStack;
private array $transformStack;

/**
* @param string|null $docWidth The original SVG document width, as a string.
Expand Down
2 changes: 1 addition & 1 deletion src/Rasterization/Transform/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class Transform
{
private $matrix;
private array $matrix;

/**
* Create a transform from the given matrix. The entries [a, b, c, d, e, f] represent the following matrix:
Expand Down
4 changes: 2 additions & 2 deletions src/Reading/AttributeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AttributeRegistry
* @var string[] @styleAttributes Attributes to be interpreted as styles.
* List comes from https://www.w3.org/TR/SVG/styling.html.
*/
private static $styleAttributes = [
private static array $styleAttributes = [
// DEFINED IN BOTH CSS2 AND SVG
// font properties
'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch',
Expand Down Expand Up @@ -49,7 +49,7 @@ class AttributeRegistry
* @var string[] $styleConverters Map of style attributes to class names
* for SVG attribute to CSS property conversion.
*/
private static $styleConverters = [
private static array $styleConverters = [
'font-size' => 'SVG\Reading\LengthAttributeConverter',
'letter-spacing' => 'SVG\Reading\LengthAttributeConverter',
'word-spacing' => 'SVG\Reading\LengthAttributeConverter',
Expand Down
2 changes: 1 addition & 1 deletion src/Reading/LengthAttributeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class LengthAttributeConverter implements AttributeConverter
{
private static $instance;
private static LengthAttributeConverter $instance;

/**
* @codeCoverageIgnore
Expand Down
2 changes: 1 addition & 1 deletion src/Reading/NodeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NodeRegistry
/**
* @var string[] $nodeTypes Map of tag names to fully-qualified class names.
*/
private static $nodeTypes = [
private static array $nodeTypes = [
'foreignObject' => 'SVG\Nodes\Embedded\SVGForeignObject',
'image' => 'SVG\Nodes\Embedded\SVGImage',

Expand Down
6 changes: 3 additions & 3 deletions src/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
class SVG
{
/** @var SVGReader $reader The singleton reader used by this class. */
private static $reader;
private static SVGReader $reader;

private static $fontRegistry;
private static FontRegistry $fontRegistry;

/** @var SVGDocumentFragment $document This image's root `svg` node/tag. */
private $document;
private SVGDocumentFragment $document;

/**
* @param mixed $width The image's width (any CSS length).
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Colors/ColorLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function get(string $keyword): ?array
* @var array[] $values A map of color names to their RGBA arrays.
* @see https://www.w3.org/TR/SVG11/types.html#ColorKeywords For the source.
*/
private static $values = [
private static array $values = [
'transparent' => [ 0, 0, 0, 0],
'aliceblue' => [240, 248, 255, 255],
'antiquewhite' => [250, 235, 215, 255],
Expand Down
2 changes: 1 addition & 1 deletion src/Writing/SVGWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class SVGWriter
{
/** @var string $outString The XML output string being written */
private $outString = '';
private string $outString = '';

public function __construct(bool $isStandalone = true)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Nodes/Shapes/SVGPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
class SVGPathTest extends \PHPUnit\Framework\TestCase
{
private static $sampleDescription = 'M100,100 h20 Z M200,200 h20';
private static $sampleCommands = [
private static string $sampleDescription = 'M100,100 h20 Z M200,200 h20';
private static array $sampleCommands = [
['id' => 'M', 'args' => [100.0, 100.0]],
['id' => 'h', 'args' => [20.0]],
['id' => 'Z', 'args' => []],
Expand Down
4 changes: 2 additions & 2 deletions tests/Rasterization/Renderers/MultiPassRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
class MultiPassRendererTest extends \PHPUnit\Framework\TestCase
{
private static $sampleOptions = [
private static array $sampleOptions = [
'option1' => 'option1-value',
'option2' => 'option2-value',
];
private static $sampleParams = [
private static array $sampleParams = [
'param1' => 'param1-value',
'param2' => 'param2-value',
];
Expand Down
4 changes: 2 additions & 2 deletions tests/SVGTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
class SVGTest extends \PHPUnit\Framework\TestCase
{
private $xml;
private $xmlNoDeclaration;
private string $xml;
private string $xmlNoDeclaration;

public function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Writing/SVGWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class SVGWriterTest extends \PHPUnit\Framework\TestCase
{
private $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>';
private string $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>';

public function testShouldIncludeXMLDeclaration()
{
Expand Down

0 comments on commit be62519

Please sign in to comment.