davidjeddy / normie
Attempt to normalize the PHP standard library array and string function parameter order.
Requires
- php: ^7.4
Requires (Dev)
- bmitch/churn-php: ^1
- dephpend/dephpend: dev-master
- friendsofphp/php-cs-fixer: ^2
- phploc/phploc: ^4
- phpmd/phpmd: ^2
- phpmetrics/phpmetrics: ^2
- phpstan/phpstan: ^0.11
- phpunit/phpunit: ^8
- povils/phpmnd: ^2
- roave/no-floaters: ^1
- roave/no-leaks: 1.1.2
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^4
- squizlabs/php_codesniffer: ^3
- wapmorgan/php-code-fixer: dev-master
This package is auto-updated.
Last update: 2024-11-17 09:59:39 UTC
README
Badges
Contributors
- David J Eddy me@davidjeddy.com
Description
Normie (short for Normalizer) attempts to make using the PHP Standard Library (SPL) function calls more consistent by implementing a norm_{function name}() wrapper function declarations. This library DOES NOT over ride the SPL functions in any way.
Examples
Function parameter order examples.
Arrays fn()
Normie array functions follow the 'array source X, operator Y (callback,key, needle, etc), other parameters are Z' mentality. The complete list of array functions are viewable here.
SPL: array array_map ( callable $callback, array $arr1, array $_ = null) { }
Normie: array norm_array_map( array $array, callable $callback, array $userdata = null): array
Strings fn()
Normie string functions follow the 'Search X string or Y target, replace with Z string' mentality. The complete list of string functions are viewable here.
SPL: array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
Normie: array explode ( string $string , string $delimiter [, int $limit = PHP_INT_MAX ] )
Install
Via Composer:
php composer.phar require davidjeddy/Normie
Library Under Development Setup
# Download repo and runtime environment git clone https://github.com/davidjeddy/normie.git cd ./normie docker pull php:7.4.0-cli docker run -d --rm --name php7_4 -v $(pwd):/normie php:7.4.0-cli tail -f /dev/null # Tools to make composer work a bit easier apt-get update -y apt-get install -y git zip unzip # Run a PHP environment docker exec -it php7_4 bash # Install deps cd /normie php composer.phar self-update php composer.phar install --dev -vvv -o # OR php composer.phar update -vvv -o
Testing / Quality / Reporting Tools
Quality
php-cs-fixer
./vendor/bin/php-cs-fixer fix ./src
phpmnd
./vendor/bin/phpmnd ./src/ --progress
phpstan
./vendor/bin/phpstan analyse ./src --level 7
phploc
./vendor/bin/phploc ./src --count-tests
phpcpd
./vendor/bin/phpcpd ./src
dephpend
./vendor/bin/dephpend metrics ./src
churn
./vendor/bin/churn run src
phpcf
./vendor/bin/phpcf ./src
Roave no leakds
vendor/bin/roave-no-leaks ./tests
Reporting
phpcs
./vendor/bin/phpcs -p ./src/ --colors --report=source --report-file=./reports/phpcs.txt
phpmd
./vendor/bin/phpmd ./src html codesize,unusedcode,naming --reportfile ./reports/phpmd.html
phpmetrics
./vendor/bin/phpmetrics --report-html=./reports ./src/
Testing
phpunit
No xDebug
./vendor/bin/phpunit --bootstrap vendor/autoload.php ./tests
With xDebug
php ./vendor/bin/phpunit ./tests --coverage-clover './reports/clover.xml'
Usage
Usage is easy! Add the namespace declaration to your logic, then any time you want to use a normilized
version of a function you know add norm_
to the beginning. Now all array and string function parameters are in a predicatable order!
<?php
namespace Your\Class\Name;
...
use Normie\Array;
use Normie\String;
...
// some code for your application
...
$results = norm_stristr($heystack, $key);
...
xDebug
For some reporting / QA xDebug is needed. To do this execute the following:
docker run -it --rm --name normie -v "$PWD":/app php:7.4.0-jessie bash
pecl install xdebugphp
echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" >> /usr/local/etc/php/conf.d/xdebug.ini