From 89dc85e8dda0649e22317b8ae65715b5da0aa614 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 16 Jun 2023 10:16:59 +0545 Subject: [PATCH 1/4] Add phan config --- .phan/config.php | 108 ++++++++++++++++++++++++++++++++++ vendor-bin/phan/composer.json | 5 ++ 2 files changed, 113 insertions(+) create mode 100644 .phan/config.php create mode 100644 vendor-bin/phan/composer.json diff --git a/.phan/config.php b/.phan/config.php new file mode 100644 index 0000000..98c5d93 --- /dev/null +++ b/.phan/config.php @@ -0,0 +1,108 @@ + + * + * @copyright Copyright (c) 2018, ownCloud GmbH + * @license GPL-2.0 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +return [ + + // Supported values: '7.2', '7.3', '7.4', '8.0', null. + // If this is set to null, + // then Phan assumes the PHP version which is closest to the minor version + // of the php executable used to execute phan. + 'target_php_version' => null, + + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in exclude_analysis_directory_list, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => [ + 'src', + 'vendor', + ], + + // A list of files to include in analysis + 'file_list' => [ + ], + + // A directory list that defines files that will be excluded + // from static analysis, but whose class and method + // information should be included. + // + // Generally, you'll want to include the directories for + // third-party code (such as "vendor/") in this list. + // + // n.b.: If you'd like to parse but not analyze 3rd + // party code, directories containing that code + // should be added to both the `directory_list` + // and `exclude_analysis_directory_list` arrays. + 'exclude_analysis_directory_list' => [ + 'vendor', + ], + + // A regular expression to match files to be excluded + // from parsing and analysis and will not be read at all. + // + // This is useful for excluding groups of test or example + // directories/files, unanalyzable files, or files that + // can't be removed for whatever reason. + // (e.g. '@Test\.php$@', or '@vendor/.*/(tests|Tests)/@') + 'exclude_file_regex' => '@.*/[^/]*(tests|Tests|templates)/@', + + // If true, missing properties will be created when + // they are first seen. If false, we'll report an + // error message. + "allow_missing_properties" => false, + + // If enabled, allow null to be cast as any array-like type. + // This is an incremental step in migrating away from null_casts_as_any_type. + // If null_casts_as_any_type is true, this has no effect. + "null_casts_as_any_type" => true, + + // Backwards Compatibility Checking. This is slow + // and expensive, but you should consider running + // it before upgrading your version of PHP to a + // new version that has backward compatibility + // breaks. + 'backward_compatibility_checks' => false, + + // The initial scan of the function's code block has no + // type information for `$arg`. It isn't until we see + // the call and rescan test()'s code block that we can + // detect that it is actually returning the passed in + // `string` instead of an `int` as declared. + 'quick_mode' => false, + + // The minimum severity level to report on. This can be + // set to Issue::SEVERITY_LOW, Issue::SEVERITY_NORMAL or + // Issue::SEVERITY_CRITICAL. Setting it to only + // critical issues is a good place to start on a big + // sloppy mature code base. + 'minimum_severity' => 5, + + // A set of fully qualified class-names for which + // a call to parent::__construct() is required + 'parent_constructor_required' => [ + ], + +]; diff --git a/vendor-bin/phan/composer.json b/vendor-bin/phan/composer.json new file mode 100644 index 0000000..9003121 --- /dev/null +++ b/vendor-bin/phan/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phan/phan": "^5.4" + } +} From 73859c771720ef0ac27342a25b48430026685d92 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 16 Jun 2023 10:18:48 +0545 Subject: [PATCH 2/4] Adjust code for problems reported by phan --- src/TarHeader.php | 6 +++--- src/TarStreamer.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TarHeader.php b/src/TarHeader.php index d4f4736..1ff3ba0 100644 --- a/src/TarHeader.php +++ b/src/TarHeader.php @@ -66,8 +66,8 @@ public function getHeader() { $fields = [ ['a100', substr($this->name, 0, 100)], ['a8', str_pad($this->mode, 7, '0', STR_PAD_LEFT)], - ['a8', decoct(str_pad($this->uid, 7, '0', STR_PAD_LEFT))], - ['a8', decoct(str_pad($this->gid, 7, '0', STR_PAD_LEFT))], + ['a8', decoct((int) str_pad($this->uid, 7, '0', STR_PAD_LEFT))], + ['a8', decoct((int) str_pad($this->gid, 7, '0', STR_PAD_LEFT))], ['a12', str_pad(decoct((int)$this->size), 11, '0', STR_PAD_LEFT)], ['a12', str_pad(decoct((int)$this->mtime), 11, '0', STR_PAD_LEFT)], // We calculate checksum later @@ -124,7 +124,7 @@ protected function packFields($fields) { * Generate unsigned checksum of header * * @param string $header - * @return string unsigned checksum + * @return float|int unsigned checksum */ protected function computeUnsignedChecksum($header) { $unsignedChecksum = 0; diff --git a/src/TarStreamer.php b/src/TarStreamer.php index 71caae6..8bbf54a 100644 --- a/src/TarStreamer.php +++ b/src/TarStreamer.php @@ -149,7 +149,7 @@ public function finalize() { * Initialize a file stream * * @param string $name file path or just name - * @param int $type type of the item + * @param int|string $type type of the item * @param int $size size in bytes of the file * @param array $opt array (optional) * Valid options are: @@ -248,7 +248,7 @@ protected function send($data) { * Generate a PAX string * * @param array $fields key value mapping - * @return string PAX formated string + * @return string PAX formatted string * @link http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5&manpath=FreeBSD+8-current tar / PAX spec */ protected function paxGenerate($fields) { @@ -256,7 +256,7 @@ protected function paxGenerate($fields) { foreach ($fields as $name => $value) { // build the line and the size $line = ' ' . $name . '=' . $value . "\n"; - $size = \strlen(\strlen($line)) + \strlen($line); + $size = \strlen((string) \strlen($line)) + \strlen($line); // add the line $lines .= $size . $line; From 4cd836e9005bead4ccc9b239d6f8436d9e79e313 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 16 Jun 2023 10:20:01 +0545 Subject: [PATCH 3/4] Enable phan in CI --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index db16ccf..0e73e9c 100644 --- a/.drone.star +++ b/.drone.star @@ -25,7 +25,7 @@ config = { ], "codestyle": True, "phpstan": False, - "phan": False, + "phan": True, "phpunit": { "php74": { "phpVersions": ["7.4"], From b50b699f98912bd49f03153b9d3689d462ab93b8 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 16 Jun 2023 10:48:53 +0545 Subject: [PATCH 4/4] Enable phpstan --- .drone.star | 2 +- Makefile | 2 +- phpstan.neon | 3 +++ src/TarHeader.php | 4 +--- vendor-bin/phpstan/composer.json | 5 +++++ 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 phpstan.neon create mode 100644 vendor-bin/phpstan/composer.json diff --git a/.drone.star b/.drone.star index 0e73e9c..aaafa11 100644 --- a/.drone.star +++ b/.drone.star @@ -24,7 +24,7 @@ config = { "master", ], "codestyle": True, - "phpstan": False, + "phpstan": True, "phan": True, "phpunit": { "php74": { diff --git a/Makefile b/Makefile index da56f94..74c5724 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ test-php-phan: vendor-bin/phan/vendor .PHONY: test-php-phpstan test-php-phpstan: ## Run phpstan test-php-phpstan: vendor-bin/phpstan/vendor - $(PHPSTAN) analyse --memory-limit=4G --configuration=./phpstan.neon --no-progress --level=5 appinfo lib + $(PHPSTAN) analyse --memory-limit=4G --configuration=./phpstan.neon --no-progress --level=5 src .PHONY: clean-deps clean-deps: diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a538f8f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,3 @@ +parameters: + bootstrapFiles: + ignoreErrors: diff --git a/src/TarHeader.php b/src/TarHeader.php index 1ff3ba0..b8ff15d 100644 --- a/src/TarHeader.php +++ b/src/TarHeader.php @@ -14,9 +14,7 @@ class TarHeader { private $size; private $mtime = ''; - - private $checksum; - + private $typeflag; private $linkname = ''; diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json new file mode 100644 index 0000000..90c99df --- /dev/null +++ b/vendor-bin/phpstan/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phpstan/phpstan": "^1.10" + } +}