diff --git a/.gitignore b/.gitignore index 5819720..34b0bbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ composer.lock .php-version +.tool-versions /vendor /.phpunit.cache .phpunit.result.cache diff --git a/PHP_VERSIONS b/PHP_VERSIONS index 4215b26..75df3c4 100644 --- a/PHP_VERSIONS +++ b/PHP_VERSIONS @@ -1,3 +1,4 @@ +8.4 8.3 8.2 8.1 diff --git a/README.md b/README.md index b38c67a..6c934cd 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,11 @@ Transparent background is also supported. - PHP 8.1 or later - Imagick PHP Extension + + Check with commands: + ```bash + php -i | grep imagick + ``` - Composer ## 4. Installation @@ -545,6 +550,6 @@ You can set transparent background like this. *Document created: 2023/05/28* -*Document updated: 2024/04/18* +*Document updated: 2025/01/02* -Copyright 2023 - 2024 macocci7 +Copyright 2023 - 2025 macocci7 diff --git a/bin/TestAndLint.sh b/bin/TestAndLint.sh index 21f3585..4a3b743 100644 --- a/bin/TestAndLint.sh +++ b/bin/TestAndLint.sh @@ -1,12 +1,11 @@ #!/usr/bin/bash # Script to Test and Lint -# - for the repository: macocci7/php-boxplot # requirement: -# - phpenv/phpenv +# - https://github.com/jdx/mise installed # - PHP versions defined in ../PHP_VERSIONS installed -CMD=phpenv +CMD=mise $CMD -v &> /dev/null if [ $? -ne 0 ]; then echo "command [${CMD}] not found!" @@ -20,46 +19,13 @@ if [ $? -ne 0 ]; then exit 1 fi -test_and_lint() { +switch_version() { echo "===========================================================" - echo "[PHP $1][phpenv local $1]" - phpenv local $1 - if [ $? -ne 0 ]; then - echo "Failed to switch version to $i. skipped." - return 1 - fi - echo "-----------------------------------------------------------" - echo "[PHP $1][php -v]" - php -v - echo "-----------------------------------------------------------" - echo "[PHP $1][parallel-lint]" - ./vendor/bin/parallel-lint src tests examples - echo "-----------------------------------------------------------" - echo "[PHP $1][neon-lint]" - ./vendor/nette/neon/bin/neon-lint conf - echo "-----------------------------------------------------------" - echo "[PHP $1][phpcs]" - ./vendor/bin/phpcs --ignore=vendor \ - --standard=phpcs.xml \ - -p \ - -s \ - . - echo "-----------------------------------------------------------" - echo "[PHP $1][phpmd]" - ./vendor/bin/phpmd \ - ./src/ ./examples/ ./tests/ text \ - phpmd.xml - echo "-----------------------------------------------------------" - echo "[PHP $1][phpstan]" - ./vendor/bin/phpstan analyze -c phpstan.neon - echo "-----------------------------------------------------------" - echo "[PHP $1][phpunit]" - ./vendor/bin/phpunit ./tests/ \ - --color=auto - echo "-----------------------------------------------------------" + echo "[PHP $1][Switching PHP version to $1]" + mise x php@$1 -- bash bin/TestAndLintSub.sh $1; } -echo "[[TesAndLint.sh]]" +echo "[[TestAndLint.sh]]" SUPPORTED_PHP_VERSIONS=PHP_VERSIONS if [ ! -f $SUPPORTED_PHP_VERSIONS ]; then @@ -74,6 +40,6 @@ if [ ! -r $SUPPORTED_PHP_VERSIONS ]; then fi STR_CMD='' while read version ; do - STR_CMD="$STR_CMD test_and_lint $version;" + STR_CMD="$STR_CMD switch_version $version;" done < $SUPPORTED_PHP_VERSIONS eval $STR_CMD diff --git a/bin/TestAndLintSub.sh b/bin/TestAndLintSub.sh new file mode 100644 index 0000000..28e2d19 --- /dev/null +++ b/bin/TestAndLintSub.sh @@ -0,0 +1,34 @@ +#!/usr/bin/bash + +# Script to Test and Lint +# requirement: +# - PHP versions defined in ../PHP_VERSIONS installed + +echo "-----------------------------------------------------------" +echo "[PHP $1][php -v]" +php -v +echo "-----------------------------------------------------------" +echo "[PHP $1][parallel-lint]" +./vendor/bin/parallel-lint src tests examples +echo "-----------------------------------------------------------" +echo "[PHP $1][neon-lint]" +./vendor/nette/neon/bin/neon-lint conf +echo "-----------------------------------------------------------" +echo "[PHP $1][phpcs]" +./vendor/bin/phpcs --ignore=vendor \ + --standard=phpcs.xml \ + -p \ + -s \ + . +#echo "-----------------------------------------------------------" +#echo "[PHP $1][phpmd]" +#./vendor/bin/phpmd \ +# ./src/ ./examples/ ./tests/ text \ +# phpmd.xml +echo "-----------------------------------------------------------" +echo "[PHP $1][phpstan]" +./vendor/bin/phpstan analyze -c phpstan.neon +echo "-----------------------------------------------------------" +echo "[PHP $1][phpunit]" +./vendor/bin/phpunit ./tests/ +echo "-----------------------------------------------------------" diff --git a/composer.json b/composer.json index 14a7691..7440aa7 100644 --- a/composer.json +++ b/composer.json @@ -1,20 +1,19 @@ { "name": "macocci7/php-boxplot", - "version": "1.3.0", + "version": "1.3.1", "description": "it's easy to use for creating boxplots.", "type": "library", "require": { "php": ">=8.1", "macocci7/php-frequency-table": "^1.4", - "fakerphp/faker": "^1.23", + "fakerphp/faker": "^1.24", "nette/neon": "^3.4", "macocci7/php-plotter2d": "^0.3" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.7", + "squizlabs/php_codesniffer": "^3.11", "phpunit/phpunit": "^10.5", - "phpmd/phpmd": "^2.15", - "phpstan/phpstan": "^1.11", + "phpstan/phpstan": "^2.1", "php-parallel-lint/php-parallel-lint": "^1.4" }, "license": "MIT", diff --git a/examples/class/CsvUtil.php b/examples/class/CsvUtil.php index 84397da..987fa1f 100644 --- a/examples/class/CsvUtil.php +++ b/examples/class/CsvUtil.php @@ -55,7 +55,7 @@ public function getDailyData($csvFileName) if (!file_exists($csvFileName)) { echo "CsvUtil::getDailyData(): '" . $csvFileName . "' does not exist.\n"; } - $csv = array_map('str_getcsv', file($csvFileName)); + $csv = array_map(fn ($fn) => str_getcsv($fn, ",", "\"", "\\"), file($csvFileName)); $groupBy = $this->groupBy($csv, "game_date", "release_speed"); foreach ($groupBy as $index => $row) { $groupBy[$index] = $this->convertString2IntegerInArray($row); diff --git a/examples/img/AdjustDisplayByArray.png b/examples/img/AdjustDisplayByArray.png index 3b5962c..867c6d1 100644 Binary files a/examples/img/AdjustDisplayByArray.png and b/examples/img/AdjustDisplayByArray.png differ diff --git a/examples/img/AdjustDisplayByMethods.png b/examples/img/AdjustDisplayByMethods.png index fc66f8b..4d7ff0d 100644 Binary files a/examples/img/AdjustDisplayByMethods.png and b/examples/img/AdjustDisplayByMethods.png differ diff --git a/examples/img/AdjustDisplayByNeon.png b/examples/img/AdjustDisplayByNeon.png index b6e2746..5887473 100644 Binary files a/examples/img/AdjustDisplayByNeon.png and b/examples/img/AdjustDisplayByNeon.png differ diff --git a/examples/img/BoxplotDetmersReid2023_01.png b/examples/img/BoxplotDetmersReid2023_01.png index 079ffde..5dfb5ea 100644 Binary files a/examples/img/BoxplotDetmersReid2023_01.png and b/examples/img/BoxplotDetmersReid2023_01.png differ diff --git a/examples/img/BoxplotDetmersReid2023_02.png b/examples/img/BoxplotDetmersReid2023_02.png index 962cfd5..4c4c8ec 100644 Binary files a/examples/img/BoxplotDetmersReid2023_02.png and b/examples/img/BoxplotDetmersReid2023_02.png differ diff --git a/examples/img/BoxplotExampleCase.png b/examples/img/BoxplotExampleCase.png index 21d8290..f096b43 100644 Binary files a/examples/img/BoxplotExampleCase.png and b/examples/img/BoxplotExampleCase.png differ diff --git a/examples/img/MultipleDataSet.png b/examples/img/MultipleDataSet.png index d7cb5af..4250225 100644 Binary files a/examples/img/MultipleDataSet.png and b/examples/img/MultipleDataSet.png differ diff --git a/examples/img/TransparentBackground.png b/examples/img/TransparentBackground.png index e4c5313..7c95ed6 100644 Binary files a/examples/img/TransparentBackground.png and b/examples/img/TransparentBackground.png differ diff --git a/src/Analyzer.php b/src/Analyzer.php index 6b9298d..37039a7 100644 --- a/src/Analyzer.php +++ b/src/Analyzer.php @@ -22,7 +22,7 @@ class Analyzer /** * @var array $parsed */ - public array $parsed; + public array $parsed = []; protected int|float $limitUpper; protected int|float $limitLower; /** @@ -150,9 +150,6 @@ public function getMean(array $data) */ public function getUcl() { - if (!is_array($this->parsed)) { - return null; - } if (!array_key_exists('ThirdQuartile', $this->parsed)) { return null; } @@ -168,9 +165,6 @@ public function getUcl() */ public function getLcl() { - if (!is_array($this->parsed)) { - return null; - } if (!array_key_exists('FirstQuartile', $this->parsed)) { return null; } @@ -186,9 +180,6 @@ public function getLcl() */ public function getOutliers() { - if (!is_array($this->parsed)) { - return null; - } if (!array_key_exists('data', $this->parsed)) { return null; } diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index b376050..b2cfbc8 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -9,7 +9,6 @@ * Config operator. * @author macocci7 * @license MIT - * @SuppressWarnings(PHPMD.ElseExpression) */ class Config { diff --git a/src/Plotter.php b/src/Plotter.php index da032f8..8b873f1 100644 --- a/src/Plotter.php +++ b/src/Plotter.php @@ -12,9 +12,6 @@ * class for analysis * @author macocci7 * @license MIT - * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) */ class Plotter extends Analyzer { @@ -192,10 +189,10 @@ private function adjustGridHeightPitch(float $gridHeightSpan): void if (!$this->gridHeightPitch) { $this->gridHeightPitch = 1; if ($this->gridHeightPitch < 0.125 * $gridHeightSpan) { - $this->gridHeightPitch = ( (int) (0.125 * $gridHeightSpan * 10)) / 10; + $this->gridHeightPitch = (int) (( (int) (0.125 * $gridHeightSpan * 10)) / 10); } if ($this->gridHeightPitch > 0.2 * $gridHeightSpan) { - $this->gridHeightPitch = ( (int) (0.200 * $gridHeightSpan * 10)) / 10; + $this->gridHeightPitch = (int) (( (int) (0.200 * $gridHeightSpan * 10)) / 10); } } } @@ -211,12 +208,12 @@ private function createCanvas(): void 'height' => $this->canvasHeight, ], viewport: $this->viewport, - plotarea: $this->plotarea, + plotarea: $this->plotarea, // @phpstan-ignore-line backgroundColor: $this->canvasBackgroundColor, ); $this->transformer = new Transformer( viewport: $this->viewport, - plotarea: $this->plotarea, + plotarea: $this->plotarea, // @phpstan-ignore-line ); } @@ -637,7 +634,7 @@ private function plotJitter(int $index, int $legend) */ private function plotLabels() { - if (!is_array($this->labels)) { + if (empty($this->labels)) { return $this; } $offset = $this->plotarea['offset']; @@ -648,8 +645,8 @@ private function plotLabels() if (!is_string($label) && !is_numeric($label)) { continue; } - $x = (int) ($baseX + ($index + 0.5) * $gridSpanX); - $y = (int) ($baseY + $this->fontSize * 1.2); + $x = (int) round($baseX + ($index + 0.5) * $gridSpanX); + $y = (int) round($baseY + $this->fontSize * 1.2); $this->canvas->drawText( text: (string) $label, x: $x, @@ -673,8 +670,8 @@ private function plotLabelX() $coord = $this->transformer->getCoord(0, 0); $offset = $this->plotarea['offset']; $baseY = $coord['y'] + $offset[1]; - $x = (int) ($this->canvasWidth / 2); - $y = (int) ($baseY + (1 - $this->frameYRatio) * $this->canvasHeight / 3); + $x = (int) round($this->canvasWidth / 2); + $y = (int) round($baseY + (1 - $this->frameYRatio) * $this->canvasHeight / 3); $this->canvas->drawText( text: (string) $this->labelX, x: $x, @@ -696,8 +693,8 @@ private function plotLabelY() { $width = $this->canvasHeight; $height = (int) ($this->canvasWidth * (1 - $this->frameXRatio) / 3); - $x = $width / 2; - $y = ($height + $this->fontSize) / 2; + $x = (int) round($width / 2); + $y = (int) round(($height + $this->fontSize) / 2); $this->canvas->drawText( text: (string) $this->labelY, x: $x, @@ -822,9 +819,6 @@ public function create(string $filePath) if (strlen($filePath) === 0) { throw new \Exception("empty string specified for file path."); } - if (!is_array($this->dataSet)) { - throw new \Exception('Invalid type of property: Plotter::$data array expected.'); - } if (empty($this->dataSet)) { throw new \Exception("Empty data specified."); } diff --git a/src/Traits/AttributeTrait.php b/src/Traits/AttributeTrait.php index d8c9a76..fcd542b 100644 --- a/src/Traits/AttributeTrait.php +++ b/src/Traits/AttributeTrait.php @@ -11,7 +11,7 @@ trait AttributeTrait /** * @var string[] $labels */ - protected array $labels; + protected array $labels = []; protected string $labelX; protected string $labelY; protected string $caption;