• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 4 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A clean interface to calculate percentages in PHP: changes between values, percentage increases, partial values, ...

A PHP package to work with percentages

A clean interface to calculate percentages in PHP: changes between values, percentage increases, partial values, extensions, ...

Think of it as a very lightweight math library for the basic stuff. Aimed to make your code more readable and easier to understand.

Installation

You can install the package via composer:

composer require mattiasgeniar/php-percentages

Usage

<?php
use Mattiasgeniar\Percentage\Percentage;

// What's the percentage increase from 100 to 120?
Percentage::differenceBetween(100, 120);            // 20%

// What's the absolute percentage change from 100 to 80?
// (uses the abs() function)
Percentage::absoluteDifferenceBetween(100, 80);     // 20%, not -20%

// How much is 120 compared to 100?
Percentage::calculate(120, 100);                    // 120%

// How much is 50 compared to 100?
Percentage::calculate(50, 100);                     // 50%

// What is 20% of 200?
Percentage::of(20, 200);                            // 40

// What is the 140% extension from 3 to 2?
Percentage::extension(140, 3, 2);                   // 1.6

// What is the 140% extension from 1 to 2?
Percentage::extension(140, 1, 2);                   // 2.4

Helper functions

The above expressions can also be used through a variety of helper functions:

  • percentage()
  • percentage_between()
  • percentage_abs_between()
  • percentage_of()
  • percentage_extension()

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

php-exploit-scripts

A collection of PHP exploit scripts, found when investigating hacked servers. These are stored for educational purposes and to test fuzzers and vulnerability scanners. Feel free to contribute.
PHP
831
star
2

varnish-4.0-configuration-templates

Configuration templates used for Varnish 4.0 implementations.
VCL
571
star
3

varnish-3.0-configuration-templates

Configuration templates used for Varnish 3.0 implementations
VCL
322
star
4

varnish-5.0-configuration-templates

A sane default configuration for Varnish 5.x
VCL
188
star
5

zabbix-orphaned-data-cleanup

Cleanup script for orphaned data in a Zabbix Database
Shell
143
star
6

varnish-6.0-configuration-templates

A sane default configuration for Varnish 6.x
VCL
131
star
7

phpunit-query-count-assertions

A custom assertion for PHPUnit that allows you to count the number of SQL queries used in a test.
PHP
94
star
8

MoZBX

Mobile Zabbix frontend for iPhone, Android, Windows Mobile, ...
PHP
69
star
9

McAfee-Shill-Bot

This bot monitors @officialmcafee's tweets, parses their text & images (using OCR), extracts the coin-ticker and buys them on BitTrex.
PHP
65
star
10

puppet-pre-commit-hook

A Puppet pre-commit hook to validate syntax
Shell
60
star
11

http-flooder

An experiment using goroutines and channels to create a simple HTTP flooder. Mixes GET, POST, PUT, PATCH, ... to one baseline URL.
Go
54
star
12

certdiff

Every tried to run 'diff' on 2 certificate files? Doesn't quite work. This tool helps resolve that: a clear report between 2 certificates, reporting all differences.
Shell
43
star
13

the-infinite-file-download

A PHP script that sends binary data to a browser. Non-stop.
HTML
27
star
14

demo-php-blocking-sessions

A small demo on how PHP handles session locking and concurrency.
HTML
26
star
15

slowloris

Slowloris - the low bandwidth, yet greedy and poisonous HTTP client
Perl
24
star
16

Varnish-URL-Purger

Some sample PHP code to purge a Varnish URL from cache
PHP
21
star
17

laravel-gitlab-ci-config

An example config for using Gitlab's pipelines (ci/cd) to test Laravel applications in phpunit.
16
star
18

Encoder

Encoding, Decoding and Obfuscating strings.
PHP
10
star
19

mojah.be

A set of resources provided for the Bitcoin community.
PHP
10
star
20

generator.cronweekly.com-v2

Second edition for the cron.weekly generator: gets all bookmarks from the Pocket API and structures the markdown.
HTML
10
star
21

rsssg

Real Simple Static Site Generator - A static site generator using native Linux tools
Shell
8
star
22

mac-bootstrap

Script to bootstrap the setup of a new Mac with default tools & configs
Shell
8
star
23

nginx-configuration-templates

Sample nginx templates used as a reference
7
star
24

bash-script-skeleton-template

A simple template that can serve as the base for future shell scripts. Contains proper handling of options, has a help function, logging capabilities, ...
Shell
7
star
25

generator.cronweekly.com

Generate the HTML and plain-text version of the cron.weekly newsletter, based on simple HTML (WordPress blogposts).
PHP
7
star
26

Mailheader-Parser

A test to parse mailheaders in a more readable format, and do some analytics on them.
PHP
6
star
27

dotfiles

personal config .files
Shell
4
star
28

http2-vs-http1-demo-sites

You heard about this thing called HTTP/2. It's supposed to be a better protocol. Faster. Safer. More unicorns. But how much better? This repo contains a couple of HTTP/1.1 vs HTTP/2 comparisons you can test.
CSS
3
star
29

apc.php

This is a blind copy of the apc.php file that is bundled with PECL's APC installation.
PHP
3
star
30

docker-containers

A dump-place for my Dockerfiles
Dockerfile
3
star
31

puppet-certificate

Manage SSL certificates through a Puppet defined type. This does not manage the Puppet CA Certificates, but SSL certificates for Apache, Nginx, ...
Puppet
2
star
32

puppet-caddy

A puppet module to manage the Caddy webserver.
2
star
33

vettigevrijdag.be

Waarom? Daarom.
CSS
2
star
34

puppet-sysdig

Install the sysdig Linux debugging tool via Puppet
Puppet
2
star
35

puppet-vagrant_helper_scripts

Set of helper scripts to ease development of Puppet modules/manifests with Vagrant.
Puppet
2
star
36

Shortlink-Revealer

A firefox extension that, upon mouseover of a URL, will show you the actual target of that URL - not the bit.ly or other shortlink.
JavaScript
2
star