From 3f858d71bd917b96dce5c848fb3ed4fc1d02f4cd Mon Sep 17 00:00:00 2001 From: smiley Date: Wed, 18 Mar 2026 02:32:53 +0100 Subject: [PATCH] :octocat: LuminanceSourceInterface: remove property getters in favor of asymmetric visibility --- src/Common/LuminanceSourceAbstract.php | 38 ++++++++++++++----------- src/Common/LuminanceSourceInterface.php | 24 +++------------- src/Decoder/Binarizer.php | 6 ++-- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/Common/LuminanceSourceAbstract.php b/src/Common/LuminanceSourceAbstract.php index 10f81923c..26b8fae06 100644 --- a/src/Common/LuminanceSourceAbstract.php +++ b/src/Common/LuminanceSourceAbstract.php @@ -27,10 +27,28 @@ use function array_slice, file_exists, is_file, is_readable, realpath; abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ protected SettingsContainerInterface|QROptions $options; - /** @var int[] */ - protected array $luminances = []; - protected int $width; - protected int $height; + + /** + * Fetches luminance data for the underlying bitmap. Values should be fetched using: + * `int luminance = array[y * width + x] & 0xff` + * + * @return int[] A row-major 2D array of luminance values. Do not use result $length as it may be + * larger than $width * $height bytes on some platforms. Do not modify the contents + * of the result. + * + * @var int[] + */ + protected(set) array $luminances = []; + + /** + * The width of the bitmap. + */ + protected(set) int $width; + + /** + * The height of the bitmap. + */ + protected(set) int $height; public function __construct(int $width, int $height, SettingsContainerInterface|QROptions $options = new QROptions){ $this->width = $width; @@ -38,18 +56,6 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ $this->options = $options; } - public function getLuminances():array{ - return $this->luminances; - } - - public function getWidth():int{ - return $this->width; - } - - public function getHeight():int{ - return $this->height; - } - public function getRow(int $y):array{ if($y < 0 || $y >= $this->height){ diff --git a/src/Common/LuminanceSourceInterface.php b/src/Common/LuminanceSourceInterface.php index 621d85924..2c30aa9b6 100644 --- a/src/Common/LuminanceSourceInterface.php +++ b/src/Common/LuminanceSourceInterface.php @@ -16,29 +16,13 @@ use chillerlan\Settings\SettingsContainerInterface; /** * Interface for the luminance sources + * + * @property int[] $luminances + * @property int $width + * @property int $height */ interface LuminanceSourceInterface{ - /** - * Fetches luminance data for the underlying bitmap. Values should be fetched using: - * `int luminance = array[y * width + x] & 0xff` - * - * @return int[] A row-major 2D array of luminance values. Do not use result $length as it may be - * larger than $width * $height bytes on some platforms. Do not modify the contents - * of the result. - */ - public function getLuminances():array; - - /** - * @return int The width of the bitmap. - */ - public function getWidth():int; - - /** - * @return int The height of the bitmap. - */ - public function getHeight():int; - /** * Fetches one row of luminance data from the underlying platform's bitmap. Values range from * 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have diff --git a/src/Decoder/Binarizer.php b/src/Decoder/Binarizer.php index 48ec9ff3f..0ecddd330 100644 --- a/src/Decoder/Binarizer.php +++ b/src/Decoder/Binarizer.php @@ -53,7 +53,7 @@ final class Binarizer{ public function __construct(LuminanceSourceInterface $source){ $this->source = $source; - $this->luminances = $this->source->getLuminances(); + $this->luminances = $this->source->luminances; } /** @@ -137,8 +137,8 @@ final class Binarizer{ * @return \chillerlan\QRCode\Decoder\BitMatrix The 2D array of bits for the image (true means black). */ public function getBlackMatrix():BitMatrix{ - $width = $this->source->getWidth(); - $height = $this->source->getHeight(); + $width = $this->source->width; + $height = $this->source->height; if($width >= self::MINIMUM_DIMENSION && $height >= self::MINIMUM_DIMENSION){ $subWidth = ($width >> self::BLOCK_SIZE_POWER);