Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
# Do not include the following files when creating repo artifacts, e.g. the zip
/.* export-ignore
/build/ export-ignore
/src/ export-ignore
/tests/ export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/phpunit.xml.dist export-ignore
/box.json export-ignore
/composer.build.json export-ignore
/composer.release.json export-ignore
/bin/build-phar.sh export-ignore
/bin/phpmnd.src export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/build
/vendor
/.phpunit.result.cache
/composer.release.json
/composer.lock
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ Afterwards make sure you have the global Composer binaries directory in your ``P
```bash
$ export PATH="$PATH:$HOME/.composer/vendor/bin"
```
### For Development

Because this repo is now a phar-first repo, you need to manually use the dev composer.json:

```
mv composer.json composer.release.json
cp composer.build.json composer.json
composer install
```

If you wish to build the phar:

```
./bin/build-phar.sh
```

If you wish to test the phar file, it will not work if there is an existing vendor directory.

## Usage Example

Expand Down Expand Up @@ -178,6 +195,11 @@ $percent = $number / intval(100);
```
would mark 100 as not magic.

## Installation




## Contributing

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
Expand Down
42 changes: 42 additions & 0 deletions bin/build-phar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

if ! command -v box 2>&1 > /dev/null; then
echo "It doesn't look like you have the box CLI installed for creating PHARs..."
read -p "Would you like to install it now? (y/N) " YES_NO
if [ "$YES_NO" != "y" ]; then
echo "Please install https://github.com/box-project/box to continue."
exit 1
fi

wget -O box.phar "https://github.com/box-project/box/releases/latest/download/box.phar"
wget -O box.phar.asc "https://github.com/box-project/box/releases/latest/download/box.phar.asc"

# Check that the signature matches
gpg --keyserver hkps://keys.openpgp.org --recv-keys 41539BBD4020945DB378F98B2DF45277AEF09A2F
gpg --verify box.phar.asc box.phar

rm box.phar.asc
mv box.phar box
chmod +x box

echo sudo mv box /usr/local/bin
sudo mv box /usr/local/bin
fi

# Run composer install to insure that everything is good.
echo "Running a fresh \`composer install --no-dev\` to insure the latest dependencies are installed..."
echo "Removing vendor/ and composer.lock ..."
rm -v composer.lock
rm -rf vendor
git checkout composer.json
mv composer.json composer.release.json
cp composer.build.json composer.json
composer install --no-dev


# Build the phar
echo "Building phpmnd.phar..."
box compile

mv composer.release.json composer.json
rm -rf vendor
56 changes: 0 additions & 56 deletions bin/createPhar

This file was deleted.

61 changes: 7 additions & 54 deletions bin/phpmnd
Original file line number Diff line number Diff line change
@@ -1,61 +1,14 @@
#!/usr/bin/env php
<?php

use Povils\PHPMND\Console\Application;
use Povils\PHPMND\Container;
declare (strict_types=1);

if (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) === false) {
echo \PHP_EOL . 'PHPMND may only be invoked from a command line, got "' . \PHP_SAPI . '"' . \PHP_EOL;

exit(1);
}

if (\version_compare('7.4.0', \PHP_VERSION, '>')) {
\fwrite(
\STDERR,
\sprintf(
'This version of PHPMND is supported on PHP 7.4.' . \PHP_EOL .
'You are using PHP %s%s.' . \PHP_EOL,
\PHP_VERSION,
\defined('PHP_BINARY') ? ' (' . \PHP_BINARY . ')' : ''
)
);
exit(1);
if (!file_exists(__DIR__ . '/phpmnd.phar') || is_dir(__DIR__ . '/../vendor')) {
// Run the internal phpmnd binary directly.
require __DIR__ . '/phpmnd.src';
exit;
}

// PHPMND autoloading
(static function (): void {
if (\file_exists($autoload = __DIR__ . '/../../../autoload.php')) {
// Is installed via Composer
include_once $autoload;

return;
}

if (\file_exists($autoload = __DIR__ . '/../vendor/autoload.php')) {
// Is installed locally
include_once $autoload;

return;
}

\fwrite(
\STDERR,
<<<'ERROR'
You need to set up the project dependencies using Composer:
$ composer install
You can learn all about Composer on https://getcomposer.org/.
ERROR
);

throw new RuntimeException('Unable to find the Composer autoloader.');
})();

// Project (third-party) autoloading
(static function (): void {
if (\file_exists($autoload = \getcwd() . '/vendor/autoload.php')) {
include_once $autoload;
}
})();
Phar::loadPhar(__DIR__ . '/phpmnd.phar', 'phpmnd.phar');

(new Application(Container::create()))->run();
require 'phar://phpmnd.phar/bin/phpmnd.src';
Binary file added bin/phpmnd.phar
Binary file not shown.
61 changes: 61 additions & 0 deletions bin/phpmnd.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env php
<?php

use Povils\PHPMND\Console\Application;
use Povils\PHPMND\Container;

if (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) === false) {
echo \PHP_EOL . 'PHPMND may only be invoked from a command line, got "' . \PHP_SAPI . '"' . \PHP_EOL;

exit(1);
}

if (\version_compare('7.4.0', \PHP_VERSION, '>')) {
\fwrite(
\STDERR,
\sprintf(
'This version of PHPMND is supported on PHP 7.4.' . \PHP_EOL .
'You are using PHP %s%s.' . \PHP_EOL,
\PHP_VERSION,
\defined('PHP_BINARY') ? ' (' . \PHP_BINARY . ')' : ''
)
);
exit(1);
}

// PHPMND autoloading
(static function (): void {
if (\file_exists($autoload = __DIR__ . '/../../../autoload.php')) {
// Is installed via Composer
include_once $autoload;

return;
}

if (\file_exists($autoload = __DIR__ . '/../vendor/autoload.php')) {
// Is installed locally
include_once $autoload;

return;
}

\fwrite(
\STDERR,
<<<'ERROR'
You need to set up the project dependencies using Composer:
$ composer install
You can learn all about Composer on https://getcomposer.org/.
ERROR
);

throw new RuntimeException('Unable to find the Composer autoloader.');
})();

// Project (third-party) autoloading
(static function (): void {
if (\file_exists($autoload = \getcwd() . '/vendor/autoload.php')) {
include_once $autoload;
}
})();

(new Application(Container::create()))->run();
3 changes: 3 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "bin/phpmnd.src"
}
50 changes: 50 additions & 0 deletions composer.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "povils/phpmnd",
"type": "application",
"description": "A tool to detect Magic numbers in codebase",
"license": "MIT",
"authors": [
{
"name": "Povilas Susinskas",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/povils/phpmnd/issues"
},
"require": {
"php": "^7.4 || ^8.0",
"composer-runtime-api": "^2.0",
"nikic/php-parser": "^4.18 || ^5.0",
"php-parallel-lint/php-console-highlighter": "^1.0",
"phpunit/php-timer": "^2.0 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/finder": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^2.8.1||^3.5"
},
"autoload": {
"psr-4": {
"Povils\\PHPMND\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Povils\\PHPMND\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"bin": [
"bin/phpmnd",
"bin/phpmnd.phar"
],
"scripts": {
"test": "phpunit",
"cs-check": "phpcs -p --standard=PSR2 --runtime-set ignore_warnings_on_exit 1 src tests --ignore=tests/Fixtures/Files",
"cs-fix": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests --ignore=tests/Fixtures/Files"
}
}
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
},
"require": {
"php": "^7.4 || ^8.0",
"composer-runtime-api": "^2.0",
"composer-runtime-api": "^2.0"
},
"require-dev": {
"nikic/php-parser": "^4.18 || ^5.0",
"php-parallel-lint/php-console-highlighter": "^1.0",
"phpunit/php-timer": "^2.0 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/finder": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"symfony/finder": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^2.8.1||^3.5"
},
Expand Down