Tool to detect assumptions

Overview

PHP Assumptions

Build Status Scrutinizer Code Quality Code Coverage

Setup

$ composer require --dev rskuipers/php-assumptions

Introduction

PHP Assumptions is the result of a proof of concept inspired by the "From assumptions to assertions" blog post. It's a static code analysis tool doing checks for weak assumptions.

This is an example of an assumption:

if ($user !== null) {
    $user->logout();
}

Running bin/phpa on this file would yield the following output:

----------------------------------------------
| file        | line | message               |
==============================================
| example.php | 3    | if ($user !== null) { |
----------------------------------------------

1 out of 1 boolean expressions are assumptions (100%)

This is an example of an assertion:

if ($user instanceof User) {
    $user->logout();
}

Tests

This project is built with PHPUnit and Prophecy. In order to run these tests make sure you have dev dependencies installed with composer.

Running PHPUnit:

$ ./vendor/bin/phpunit
Comments
  • Tests break when using Generator Return Expressions from PHP 7.0

    Tests break when using Generator Return Expressions from PHP 7.0

    I just wanted to create this issue here for visibility for anyone who might have the same issue. Due to an issue in the nikic/PHP-Parser package if you use self-executing anonymous functions the tests break and throw an error.

    Full details can be seen here: nikic/PHP-Parser#316

    opened by mallardduck 5
  • Php7 compatibility update

    Php7 compatibility update

    This set of commits fixes the issue of #15 that I recently reported.

    All tests were passing still on my end and this now allows me to run with out commenting out GREs. However once I started using ./vendor/bin/phpunit I got all sorts of errors in tests. I made an attempt at fixing most of them but I wasn't familiar enough with the packing and how to properly fix the remaining test that has issues.

    opened by mallardduck 3
  • Deprecated error: passing `null` to `strlen`

    Deprecated error: passing `null` to `strlen`

    I tried the v0.8.0 on one of my project and I got the following error

    Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/www/vendor/rskuipers/php-assumptions/src/PhpAssumptions/Cli.php on line 138
    

    I ran the project in a docker container that own a PHP 8.1 version.

    To fix it, the following line : https://github.com/rskuipers/php-assumptions/blob/master/src/PhpAssumptions/Cli.php#L138

    could definitly be replaced by

    if ($list !== '') {
    

    as the only purpose of the usage of strlen here is to check if the string is not empty.

    EDIT: the only usage I found is actually here: https://github.com/rskuipers/php-assumptions/blob/10f82ca2a268d6624553d2de4659ed6451d9ac60/src/PhpAssumptions/Cli.php#L105

    After a quick look at \League\CLImate\Argument\Manager::get method, I found out it can return null. As the argument of getPathsFromList is supposed to be a string (read from PHPDoc + inferred from usage in the method), I think a cast should be executed while passing the argument:

    $excludes = $this->getPathsFromList((string)$this->cli->arguments->get('exclude'));
    

    Indeed, the return type of \League\CLImate\Argument\Manager::get is string|int|float|bool|null, all of them castable to string.

    opened by niconoe- 2
  • Build for PHP 7.3 and run travis unit tests simultaneously

    Build for PHP 7.3 and run travis unit tests simultaneously

    Hey 👋

    PHP 7.3 is released 🎉. I happened to stumble upon this repo and thought it would be a quick nifty addition.

    Let me know if you need any changes.

    opened by nstapelbroek 2
  • Add an option to ignore paths

    Add an option to ignore paths

    Add an option to allow some files (or directories) to be excluded from the analyze.

    I encounter a case where I wanted to check a project root path, but I get a lots of errors from the vendor directory.

    opened by MacFJA 1
  • Unable to install stable version due to nikic/php-parser 2.0

    Unable to install stable version due to nikic/php-parser 2.0

    Composer refuses to install stable version of PHP Assumptions because my project requires nikic/php-parser ^3.0.

    I can see that it is fixed in a9ca134e598d9e361c713332e1aa62400fdadf97, and I was able to install rskuipers/php-assumptions:dev-master, but I would prefer to use a stable version.

    Could you please release a new stable version?

    opened by EvgenyOrekhov 1
  • Refactor to CLImate for better argument parsing and output

    Refactor to CLImate for better argument parsing and output

    This PR introduces CLImate to the project, this is in preparation for new XmlOutput to give the option to switch format with CLI argument.

    CLImate also offers nice output so the PrettyOutput has been updated to output a table instead.

    Closes #7

    opened by rskuipers 1
  • Remove PhpSpec in favor of PHPUnit with Prophecy

    Remove PhpSpec in favor of PHPUnit with Prophecy

    PhpSpec doesn't offer much that PHPUnit with Prophecy can't provide. For the sake of using one tool for our tests, we should remove PhpSpec and convert any existing tests over to PHPUnit.

    enhancement 
    opened by rskuipers 0
  • Update Example in documentation?

    Update Example in documentation?

    The example in documentation is a bit confusing as it's out of context. It wouldn't make immediate sense to those using mostly strict type hinting.

    It needs to have the user class coming from something that could return another class type to make it absolutely clear.

    A simpler way to describe it is instead of using assumption / assertion is to check for that it actually needs to be, that makes it clearly what's happening and if for example type hinting elsewhere already provides that guarantee.

    opened by joeyhub 4
  • phpa complains about comparing DateTimeImmutable

    phpa complains about comparing DateTimeImmutable

    Suppose I have two DateTimeImmutable objects, let's say $a and $b, and I want to check whether they are referring to the same point in time.

    You can't user $a === $b for this, because that would always return false. But if you use $a == $b, phpa will complain.

    Any suggestions about how to work around this problem?

    opened by johanv 0
  • doesn't exclude ./vendor

    doesn't exclude ./vendor

    I'm running Assumptions with the following command on windows 10:

    tool-assumptions --exclude=./vendor ./

    And i get this error:

    PHP Fatal error: Uncaught PhpParser\Error: Syntax error, unexpected '{', expecting T_STRING on line 2 in C:\Users\vheidemann\projects\ci-tool-installer\assumptions\vendor\nikic\php-parser\lib\PhpParser\ParserAbstract.php:293

    Stack trace:

    #0 C:\Users\vheidemann\projects\ci-tool-installer\assumptions\vendor\nikic\php-parser\lib\PhpParser\Parser\Multiple.php(50): PhpParser\ParserAbstract->parse('<?php\nclass {CL...', Object(PhpParser\ErrorHandler\Throwing)) #1 C:\Users\vheidemann\projects\ci-tool-installer\assumptions\vendor\nikic\php-parser\lib\PhpParser\Parser\Multiple.php(31): PhpParser\Parser\Multiple->tryParse(Object(PhpParser\Parser\Php7), Object(PhpParser\ErrorHandler\Throwing), '<?php\nclass {CL...') #2 C:\Users\vheidemann\projects\ci-tool-installer\assumptions\src\PhpAssumptions\Analyser.php(71): PhpParser\Parser\Multiple->parse('<?php\nclass {CL...') #3 C:\Users\vheidemann\projects\ci-tool-installer\assumptions\src\PhpAssumptions\Cli.php(120): PhpAssumptions\Analyser->analyse(Array) #4 C:\Users\vheidemann\projects\ci-t in C:\Users\vheidemann\projects\ci-tool-installer\assumptions\vendor\nikic\php-parser\lib\PhpParser\ParserAbstract.php on line 293

    Any ideas what to do?

    opened by Volker89 0
  • Allow assertions for early exit strategies

    Allow assertions for early exit strategies

    This would be reported:

    <?php
    
    if ( 'cli' !== PHP_SAPI ) {  // THIS LINE
      throw new \Exception('only from CLI');
    }
    
    echo 'hi';
    

    We check if the current system state is something that we can work with. In general we reject everything except the one working thing which is an assertion IMHO.

    This wouldn't be reported:

    
    <?php
    
    if ( 'cli' === PHP_SAPI ) {
      echo 'hi';
    } else {
      throw new \Exception('CLI!');
    }
    

    Which makes the code unreadable if you think of 4-5 paths which are then nested damn deep. Also PHPMD may nag about the "else" and the linux kernel standards says

    Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.

    So please tell me how we can avoid the first expression to be marked as an "assumption".

    opened by ScreamingDev 3
  • Call to undefined function PhpParser\canonicalize()

    Call to undefined function PhpParser\canonicalize()

    Hi,

    I am trying out this tool and when running it, I get this error, any ideas what I could do about this?

    Call to undefined function PhpParser\canonicalize() in /php_assumptions/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php on line 17

    opened by webgast 1
Releases(0.8.1)
  • 0.8.1(Feb 15, 2022)

    What's Changed

    • Fix #37 by @niconoe- in https://github.com/rskuipers/php-assumptions/pull/38

    New Contributors

    • @niconoe- made their first contribution in https://github.com/rskuipers/php-assumptions/pull/38

    Full Changelog: https://github.com/rskuipers/php-assumptions/compare/0.8.0...0.8.1

    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(Mar 1, 2018)

Owner
Rick Kuipers
Rick Kuipers
Rules to detect game engines and other technologies based on Steam depot file lists

SteamDB File Detection Rule Sets This is a set of scripts that are used by SteamDB to make educated guesses about the engine(s) & technology used to b

Steam Database 103 Dec 14, 2022
Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture before they drag you down into the depths of dependency hell ... What it does System Requirements Installation Phive

Michael Haeuslmann 507 Dec 27, 2022
Library allows to detect emoji, remove emoji, encode emoji and decode emoji in string.

It allows to detect emoji, remove emoji, encode emoji and decode emoji in string. Installation composer require anisimov/emoji How to use Encode and

Aleksey Anisimov 9 Nov 8, 2022
Helps detect the user's browser and platform at the PHP level via the user agent

cbschuld/browser.php Helps detect the user's browser and platform at the PHP level via the user agent Installation You can add this library as a local

Chris Schuld 574 Dec 16, 2022
Mobile detect change theme and redirect based on device type. Magento 2 module.

Magento 2 Mobile Detect Theme Change Magento 2 Mobile detect system can be used to load different themes base on the client device (desktop, tablet, m

EAdesign 27 Jul 5, 2022
The main scope of this extension is to help phpstan to detect the type of object after the Assert\Assertion validation.

PHPStan beberlei/assert extension PHPStan beberlei/assert Description The main scope of this extension is to help phpstan to detect the type of object

PHPStan 33 Jan 2, 2023
Banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana detect adblock :Detects ad blockers (AdBlock, ublock, ...)

banana 24 Dec 28, 2022
Detect the position of a face in an image.

Face Detector PHP GD 를 이용해 이미지의 얼굴 위치를 식별합니다. mauricesvay/php-facedetection 프로젝트를 기반으로 만들었습니다. js 로 포팅하며 개선한 사항들을 적용하여 error_reporting = E_ALL safe 하게

Song Hyo Jin 4 Jul 27, 2022
PHP_Depend is an adaptation of the established Java development tool JDepend. This tool shows you the quality of your design in terms of extensibility, reusability and maintainability.

PHP Depend Documentation PHP Depend for enterprise Available as part of the Tidelift Subscription. The maintainers of PHP Depend and thousands of othe

PHP_Depend 837 Dec 14, 2022
RMT is a handy tool to help releasing new version of your software

RMT - Release Management Tool RMT is a handy tool to help releasing new versions of your software. You can define the type of version generator you wa

Liip 442 Dec 8, 2022
A tool for creating configurable dumps of large MySQL-databases.

slimdump slimdump is a little tool to help you create configurable dumps of large MySQL-databases. It works off one or several configuration files. Fo

webfactory GmbH 176 Dec 26, 2022
Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

National Library of Finland 195 Dec 24, 2022
This tool is used to build and maintain browscap files.

Browser Capabilities Project This tool is used to build and maintain browscap files.

Browser Capabilities Project 400 Dec 29, 2022
This tool can help you to see the real IP behind CloudFlare protected websites.

CrimeFlare Bypass Hostname Alat untuk melihat IP asli dibalik website yang telah dilindungi CloudFlare. Introduction Alat ini berfungsi untuk melakuka

zidan rahmandani 126 Oct 20, 2021
Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

Rafel is Remote Access Tool Used to Control Victims Using WebPanel With More Advance Features..

swagkarna 690 Dec 28, 2022
Standards Alignment Tool

Standards Alignment Tool (SALT) [] Overview This is a prototype for testing the IMS Global Learning Consortium® CASE™ Specification and proving its us

OpenSALT 39 Dec 14, 2022
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

netz98 758 Dec 28, 2022
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
CC [CREDIT CARD] GENERATE & VALIDATE TOOL !

⚡ CCE THIS TOOL PERMIT YOU TO GENERATE CREDIT CARD & VALIDATE

BASILEOLUS 2 Sep 19, 2021