phariscope/safephp

A PHP library complementary to SafePHP containing currently unsupported functions.

1.0.2 2023-11-26 05:31 UTC

This package is auto-updated.

Last update: 2024-04-26 06:41:52 UTC


README

A set of core PHP functions rewritten to throw exceptions instead of returning false when an error is encountered.

These functions complement those of the excellent SafePHP tool https://github.com/thecodingmachine/safe.

Installation

composer require phariscope/safephp

Usage

use function SafePHP\boolval;
use function SafePHP\floatval;
use function SafePHP\intval;
use function SafePHP\strval;

use function SafePHP\hash_file;

use function SafePHP\getenv;
use function SafePHP\getenvOrWithENV;

$value = boolval(1); // return true
$value = floatval("123.456"); // return 123.456
$value = intval("123"); // return 123
$value = strval(1); // return "1"

$value = hash_file("md2", $filename); // return a string like "080bf15137e26254e9cd8870b68aec86"

$value = getenv('PWD'); // return string of current PWD
$value = getenv(); // return array of all getenv (be carreful some $_ENV may hav been forgotten) 

$value = getenvOrWithENV('PWD'); // return string of current PWD even if it is in $_ENV only

To Contribute to phariscope/SafePHP

Requirements

  • docker
  • git

Install

Unit test

bin/phpunit

Using Test-Driven Development (TDD) principles (thanks to Kent Beck and others), following good practices (thanks to Uncle Bob and others).

Quality

  • phpcs PSR12
  • phpstan level 9
  • coverage 100%
  • infection MSI >99%

Quick check with:

./codecheck

Check coverage with:

bin/phpunit --coverage-html var

and view 'var/index.html' with your browser

Check infection with:

bin/infection

and view 'var/infection.html' with your browser