Skip to content

Commit

Permalink
most used conditions command (#1)
Browse files Browse the repository at this point in the history
- added command
  • Loading branch information
isfett authored Aug 9, 2019
1 parent b8e4953 commit a1ab216
Show file tree
Hide file tree
Showing 267 changed files with 14,088 additions and 488 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea/
/codecoverage/
/vendor/
/var/
php-analyzer.phar
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

php:
- '7.1'
- '7.2'
- '7.3'
- '7.4snapshot' # beta1
#- nightly #8 (symfony does not support php 8 yet)

before_install:
- travis_retry composer install --no-interaction --prefer-source --dev

script:
- vendor/bin/phpunit --testsuite=unit,integration --coverage-clover=coverage.xml

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email:
- [email protected]
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# How to contribute

Thanks for considering to contribute to `php-analyzer`. While doing so please follow these guidelines:

- You must follow the `isfett-coding-standard` ([link](https://www.github.com/isfett/coding-standard)). Add the phpcs and phpmd settings to your ide. If you use PhpStorm import the inspections.xml also.
- All non trivial features or bugfixes must have an associated issue for discussion. If you want to work on an issue that is already created, please leave a comment on it indicating that you are working on it.
- Add tests for features or bugfixes touching `src` code if you want to increase the chance of your contribution being merged.
- You must use [feature / topic branches](https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows) to ease the merge of your contribution.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Christopher Stenke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
php-analyzer
[![Build Status](https://img.shields.io/travis/isfett/php-analyzer/master?style=flat-square)](https://travis-ci.org/isfett/php-analyzer)
[![codecov](https://img.shields.io/codecov/c/github/isfett/php-analyzer?style=flat-square)](https://codecov.io/gh/isfett/php-analyzer)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://php.net/)
[![Latest Stable Version](https://poser.pugx.org/isfett/php-analyzer/v/stable)](https://packagist.org/packages/isfett/php-analyzer)
[![Total Downloads](https://poser.pugx.org/isfett/php-analyzer/downloads)](https://packagist.org/packages/isfett/php-analyzer)
# PHP-Analyzer

`php-analyzer` is a tool that aims to help you for different tasks. Mostly I found that I want to resolve them while doing my job. For details check the documented commands below.

## Installation
Run
```
$ composer global require isfett/php-analyzer
```
or download the latest phar from [this repository](https://github.com/isfett/php-analyzer/releases).

## Usage
For usages of the commands, check the documentation of each command.

## Information
This tool uses [a php parser written in php](https://github.com/nikic/PHP-Parser), ignoring different code-style or whitespaces.

## Commands
- [Most used conditions](docs/MostUsedConditions.md) Helps to check which conditions are used the most in your project. Just want to check if's? Or ternaries? No Problem! You can also split by logical operators, or split isset functions for each parameter. Including post-processing your conditions, flip-checking etc. You can find many examples within the link.

## Planned
- Magic Number Detector
- Magic String Detector
- Find duplicate code (ignoring codestyle, just checking statements)

## Contributing
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

## License
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
51 changes: 51 additions & 0 deletions bin/phar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env php
<?php

require 'vendor/autoload.php';
use Symfony\Component\Finder\Finder;
use Isfett\PhpAnalyzer\Kernel;

// The php.ini setting phar.readonly must be set to 0
$pharFilename = 'php-analyzer.phar';

// clean up
if (file_exists($pharFilename)) {
unlink($pharFilename);
}

// Make vendor with no dev requirements
shell_exec('composer update --no-dev --quiet');

// delete cache+logs
shell_exec('rm -R var');

// Build container
$kernel = new Kernel('prod', false);
$kernel->boot();

$finder = (new Finder())
->files()
->in(dirname(__DIR__))
->notName('phar.php')
->exclude(['codecoverage', 'docs', 'tests']);

// create phar
$phar = new Phar($pharFilename);

// creating our library using whole directory
$phar->buildFromIterator($finder->getIterator(), dirname(__DIR__));

// pointing main file which requires all classes
$phar->setStub(
"#!/usr/bin/env php
<?php
putenv('APPLICATION_ENV=prod');
Phar::mapPhar('$pharFilename');
require 'phar://$pharFilename/bin/php-analyzer.php';
__HALT_COMPILER();"
);

// reset vendor with dev requirements
shell_exec('composer update --quiet');

echo sprintf('%s successfully created', $pharFilename) . PHP_EOL;
4 changes: 4 additions & 0 deletions bin/php-analyzer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env php
<?php

require 'php-analyzer.php';
7 changes: 7 additions & 0 deletions bin/php-analyzer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

if "%PHP_PEAR_PHP_BIN%" neq "" (
set PHPBIN=%PHP_PEAR_PHP_BIN%
) else set PHPBIN=php

"%PHPBIN%" "%~dp0\php-analyzer.php" %*
21 changes: 17 additions & 4 deletions bin/php-analyzer.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env php
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';

use Isfett\PhpAnalyzer\Kernel;
use Isfett\PhpAnalyzer\Console\Application;
use Symfony\Component\EventDispatcher\EventDispatcher;

$environment = $_SERVER['APPLICATION_ENV'] ?? 'dev';
if (false !== getenv('APPLICATION_ENV')) {
$environment = getenv('APPLICATION_ENV');
}
$isDebug = 'dev' === $environment;

require_once 'vendor/autoload.php';
$dispatcher = new EventDispatcher();
$kernel = new Kernel($environment, $isDebug);
$kernel->boot();

$application = new Application();
$application->run();
$container = $kernel->getContainer();
$application = $container->get(Application::class);
$application->setDispatcher($dispatcher);
$application->run();
17 changes: 14 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
"support": {
"issues": "https://github.com/isfett/php-analyzer/issues"
},
"bin": ["bin/php-analyzer", "bin/php-analyzer.bat", "bin/php-analyzer.php"],
"require": {
"php": "^7.1",
"symfony/console": "^4.0"
"symfony/console": "^4.0",
"symfony/finder": "^4.0",
"nikic/php-parser": "^4.2",
"symfony/dependency-injection": "^4.3",
"symfony/config": "^4.3",
"symfony/http-kernel": "^4.3",
"symfony/yaml": "^4.3",
"doctrine/collections": "^1.6",
"symfony/event-dispatcher": "^4.3",
"symfony/serializer": "4.4.x-dev"
},
"require-dev": {
"isfett/coding-standard": "^1.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0 | ^8.0"
},
"autoload": {
"psr-4": {
Expand All @@ -28,5 +38,6 @@
"psr-4": {
"Isfett\\PhpAnalyzer\\Tests\\": "tests/"
}
}
},
"minimum-stability": "dev"
}
Loading

0 comments on commit a1ab216

Please sign in to comment.