coral-media / php-ml

Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library.
MIT License
1 stars 1 forks source link

Update version for phpstan tool and fix encountered errors #9

Closed rernesto closed 4 months ago

rernesto commented 4 months ago

Update phpstan/* tools to latest stable version. Update config as required and fix following errors:

vendor/bin/phpstan --level=5 --error-format=prettyJson analyse src/
{
    "totals": {
        "errors": 5,
        "file_errors": 11
    },
    "files": {
        "/srv/app/src/Classification/DecisionTree.php": {
            "errors": 1,
            "messages": [
                {
                    "message": "Casting to array something that's already array.",
                    "line": 295,
                    "ignorable": true,
                    "identifier": "cast.useless"
                }
            ]
        },
        "/srv/app/src/Classification/KNearestNeighbors.php": {
            "errors": 1,
            "messages": [
                {
                    "message": "Casting to array<int> something that's already array<int>.",
                    "line": 48,
                    "ignorable": true,
                    "tip": "Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.",
                    "identifier": "cast.useless"
                }
            ]
        },
        "/srv/app/src/Clustering/KMeans/Cluster.php": {
            "errors": 1,
            "messages": [
                {
                    "message": "Return type mixed of method Phpml\\Clustering\\KMeans\\Cluster::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate::getIterator().",
                    "line": 103,
                    "ignorable": false,
                    "tip": "Make it covariant, or use the #[\\ReturnTypeWillChange] attribute to temporarily suppress the error.",
                    "identifier": "method.tentativeReturnType"
                }
            ]
        },
        "/srv/app/src/Math/LinearAlgebra/EigenvalueDecomposition.php": {
            "errors": 3,
            "messages": [
                {
                    "message": "Comparison operation \"<\" between int<0, max> and 0 is always false.",
                    "line": 560,
                    "ignorable": true,
                    "identifier": "smaller.alwaysFalse"
                },
                {
                    "message": "For loop initial assignment overwrites variable $n.",
                    "line": 818,
                    "ignorable": true,
                    "identifier": "for.variableOverwrite"
                },
                {
                    "message": "Comparison operation \"<\" between int<0, max> and 0 is always false.",
                    "line": 941,
                    "ignorable": true,
                    "identifier": "smaller.alwaysFalse"
                }
            ]
        },
        "/srv/app/src/Math/Statistic/ANOVA.php": {
            "errors": 1,
            "messages": [
                {
                    "message": "Casting to int something that's already int<0, max>.",
                    "line": 34,
                    "ignorable": true,
                    "tip": "Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.",
                    "identifier": "cast.useless"
                }
            ]
        },
        "/srv/app/src/Metric/ClassificationReport.php": {
            "errors": 3,
            "messages": [
                {
                    "message": "Casting to float something that's already float.",
                    "line": 121,
                    "ignorable": true,
                    "identifier": "cast.useless"
                },
                {
                    "message": "Casting to float something that's already float.",
                    "line": 121,
                    "ignorable": true,
                    "identifier": "cast.useless"
                },
                {
                    "message": "Casting to array<int> something that's already array<int>.",
                    "line": 224,
                    "ignorable": true,
                    "tip": "Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.",
                    "identifier": "cast.useless"
                }
            ]
        },
        "/srv/app/src/SupportVectorMachine/DataTransformer.php": {
            "errors": 1,
            "messages": [
                {
                    "message": "Casting to string something that's already string.",
                    "line": 65,
                    "ignorable": true,
                    "tip": "Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.",
                    "identifier": "cast.useless"
                }
            ]
        }
    },
    "errors": [
        "Ignored error pattern missingType.iterableValue was not matched in reported errors.",
        "Ignored error pattern missingType.generics was not matched in reported errors.",
        "Ignored error pattern #Property Phpml\\\\Clustering\\\\KMeans\\\\Cluster\\:\\:\\$points \\(iterable\\<Phpml\\\\Clustering\\\\KMeans\\\\Point\\>\\&SplObjectStorage\\) does not accept SplObjectStorage# was not matched in reported errors.",
        "Ignored error pattern #ReflectionClass# in paths: /srv/app/src/Classification/Ensemble/AdaBoost.php, /srv/app/src/Classification/Ensemble/Bagging.php was not matched in reported errors.",
        "Ignored error pattern #Method Phpml\\\\Classification\\\\DecisionTree::getBestSplit\\(\\) should return Phpml\\\\Classification\\\\DecisionTree\\\\DecisionTreeLeaf but returns Phpml\\\\Classification\\\\DecisionTree\\\\DecisionTreeLeaf\\|null# was not matched in reported errors."
    ]
}