diff --git a/.gitattributes b/.gitattributes index 75cec1e..a2648e6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,5 +3,6 @@ /phpunit.xml.dist export-ignore /phpunit.7.5.xml export-ignore /tests/ export-ignore +/phpstan.neon.dist export-ignore /.github/ export-ignore /Docs/ export-ignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1293acd..2e28dc7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} steps: - name: Checkout @@ -32,3 +32,8 @@ jobs: else vendor/bin/phpunit fi + - name: Phpstan + run: | + if [ 1 -eq "$(echo "${{ matrix.php-versions }} > 7.1" | bc)" ]; then + vendor/bin/phpstan + fi diff --git a/.gitignore b/.gitignore index 5b3201d..3f1fe1e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ nbproject* /phpunit.xml /.phpunit.cache/ .unlock_css_optimiser +/phpstan.neon diff --git a/class.csstidy.php b/class.csstidy.php index d15c585..29a8d33 100644 --- a/class.csstidy.php +++ b/class.csstidy.php @@ -213,7 +213,7 @@ class csstidy { * @access private */ public $from = array(); - /** + /** * =true if in invalid at-rule * @var bool @@ -254,8 +254,10 @@ class csstidy { /** * Various CSS Data for CSSTidy * @var array + * + * @todo array{csstidy:array} */ - public $data = array(); + public $data; public $template; @@ -266,6 +268,7 @@ class csstidy { */ public function __construct() { $data = array(); + // $data = ['csstidy' => []]; include(__DIR__ . DIRECTORY_SEPARATOR . 'data.inc.php'); $this->data = $data; @@ -309,6 +312,7 @@ public function __construct() { $this->set_cfg('template','default'); // call load_template $this->optimise = new csstidy_optimise($this); + // @phpstan-ignore-next-line $this->tokens_list = & $this->data['csstidy']['tokens']; } @@ -358,7 +362,7 @@ public function _load_template($template) { /** * Set the value of a setting. - * @param string $setting + * @param array|string $setting * @param mixed $value * @access public * @return bool @@ -575,6 +579,8 @@ public function is_token(&$string, $i) { */ public function parse($string) { // Temporarily set locale to en_US in order to handle floats properly + // @todo Something $old = @setlocale(LC_ALL, '0'); + // @see https://www.php.net/manual/en/function.setlocale.php#locales $old = @setlocale(LC_ALL, 0); @setlocale(LC_ALL, 'C'); @@ -1091,6 +1097,7 @@ public function css_add_property($media, $selector, $property, $new_val) { */ public function css_check_last_media_section_or_inc($media) { // are we starting? + // @phpstan-ignore-next-line if (!$this->css || !is_array($this->css) || empty($this->css)) { return $media; } @@ -1119,7 +1126,7 @@ public function css_check_last_media_section_or_inc($media) { * to avoid merging * * @param string $current_media - * @param string $media + * @param string $new_media * @param bool $at_root * @return string */ @@ -1233,6 +1240,7 @@ public function css_new_property($media, $selector, $property) { */ public function merge_css_blocks($media, $selector, $css_add) { foreach ($css_add as $property => $value) { + // @phpstan-ignore-next-line $this->css_add_property($media, $selector, $property, $value, false); } } @@ -1321,7 +1329,7 @@ public function property_is_valid($property) { * format("abc",'def') => format("abc","def") * format("abc, def, ghi") => format("abc, def, ghi") * - * @param string + * @param string $value * @return array */ public function parse_string_list($value) { diff --git a/class.csstidy_optimise.php b/class.csstidy_optimise.php index a94b7cd..1878e74 100644 --- a/class.csstidy_optimise.php +++ b/class.csstidy_optimise.php @@ -56,7 +56,7 @@ class csstidy_optimise { /** * Constructor - * @param array $css contains the class csstidy + * @param csstidy $css contains the class csstidy * @access private * @version 1.0 */ @@ -473,7 +473,7 @@ public function compress_numbers($subvalue) { * Checks if a given string is a CSS valid number. If it is, * an array containing the value and unit is returned * @param string $string - * @return array ('unit' if unit is found or '' if no unit exists, number value) or false if no number + * @return array|false ('unit' if unit is found or '' if no unit exists, number value) or false if no number */ public function AnalyseCssNumber($string) { // most simple checks first @@ -516,7 +516,7 @@ public function AnalyseCssNumber($string) { * Merges selectors with same properties. Example: a{color:red} b{color:red} -> a,b{color:red} * Very basic and has at least one bug. Hopefully there is a replacement soon. * @param array $array - * @return array + * @return void * @access public * @version 1.2 */ @@ -637,7 +637,7 @@ public function dissolve_4value_shorthands($property, $value, $shorthands = null * @param string $value * @return array * @version 1.0 - * @use dissolve_4value_shorthands() + * @uses dissolve_4value_shorthands() * @see merge_4value_radius_shorthands() */ public function dissolve_4value_radius_shorthands($property, $value) { @@ -750,7 +750,7 @@ public function merge_4value_shorthands($array, $shorthands = null) { * @param array $array * @return array * @version 1.2 - * @use merge_4value_shorthands() + * @uses merge_4value_shorthands() * @see dissolve_4value_radius_shorthands() */ public function merge_4value_radius_shorthands($array) { @@ -1043,6 +1043,7 @@ public function merge_font($input_css) { // Skip if not font-family and font-size set if (isset($input_css['font-family']) && isset($input_css['font-size']) && $input_css['font-family'] != 'inherit') { // fix several words in font-family - add quotes + // @phpstan-ignore-next-line if (isset($input_css['font-family'])) { $families = explode(',', $input_css['font-family']); $result_families = array(); diff --git a/class.csstidy_print.php b/class.csstidy_print.php index 2567342..077cf08 100644 --- a/class.csstidy_print.php +++ b/class.csstidy_print.php @@ -75,7 +75,7 @@ class csstidy_print { /** * Constructor - * @param array $css contains the class csstidy + * @param csstidy $css contains the class csstidy * @access private * @version 1.0 */ @@ -446,7 +446,7 @@ public function get_ratio() { /** * Get difference between the old and new code in bytes and prints the code if necessary. * @access public - * @return string + * @return int|string * @version 1.1 */ public function get_diff() { diff --git a/composer.json b/composer.json index 84e39f9..37d18f4 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "php": "^7.1 || ^8" }, "require-dev": { + "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5 || ^10.5" }, "autoload": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..aab4991 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..6e9c8df --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,10 @@ +includes: + - phpstan-baseline.neon + +parameters: + phpVersion: 70100 + paths: + - class.csstidy.php + - class.csstidy_optimise.php + - class.csstidy_print.php + level: 4