Skip to content

Commit

Permalink
Improvements for version 3: Add getAllIPAddresses, JsonSerialize inte…
Browse files Browse the repository at this point in the history
…rface; refactor reports; add flexible reporting interface; improve build and static analysis tools.
  • Loading branch information
markrogoyski committed Oct 27, 2018
1 parent b7b94dc commit 20a8c9b
Show file tree
Hide file tree
Showing 10 changed files with 987 additions and 214 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
Expand All @@ -13,6 +12,7 @@ script:
- mkdir -p build/logs
- vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover build/logs/clover.xml
- vendor/bin/phpcs --ignore=vendor --standard=coding_standard.xml .
- vendor/bin/phpstan analyze --level max src/

after_success:
- travis_retry php vendor/bin/coveralls
- travis_retry php vendor/bin/php-coveralls -v
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY : tests lint static report coverage

all : tests lint static report

tests :
vendor/bin/phpunit tests/ --configuration=tests/phpunit.xml

lint :
vendor/bin/phpcs --standard=coding_standard.xml --ignore=vendor .

static :
vendor/bin/phpstan analyze --level max src/ tests/
vendor/bin/phpmd src/ text cleancode,codesize,design,unusedcode,naming

coverage :
vendor/bin/phpunit tests/ --configuration=tests/phpunit.xml --coverage-text=php://stdout

report :
vendor/bin/phploc src/
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Given an IP address and CIDR network size, it calculates the network information
* IP address range
* Broadcast address
* Min and max host
* All IP addresses

Provides each data in dotted quads, hexadecimal, and binary formats, as well as array of quads.

Expand All @@ -31,6 +32,9 @@ Provides each data in dotted quads, hexadecimal, and binary formats, as well as
* String
* Printed to STDOUT

### Standard Interfaces
* JsonSerializable

Setup
-----

Expand All @@ -39,7 +43,7 @@ Setup
```javascript
{
"require": {
"markrogoyski/ipv4-subnet-calculator": "2.*"
"markrogoyski/ipv4-subnet-calculator": "3.*"
}
}
```
Expand All @@ -57,8 +61,14 @@ Composer will install IPv4 Subnet Calculator inside your vendor folder. Then you
require_once(__DIR__ . '/vendor/autoload.php');
```

Alternatively, use composer on the command line to require and install IPv4 SubnetCalculator:

```
$ php composer.phar require markrogoyski/ipv4-subnet-calculator:3.*
```

### Minimum Requirements
* PHP 5.3.0
* PHP 5.5

Usage
-----
Expand Down Expand Up @@ -124,6 +134,17 @@ $max_host_hex = $sub->getMaxHostHex(); // C0A871FE
$max_host_binary = $sub->getMaxHostBinary(); // 11000000101010000111000111111110
```

### All IP Addresses
```php
foreach ($sub->getAllIPAddresses() as $ip_address) {
echo $ip_address;
}

foreach ($sub->getAllHostIPAddresses() as $host_address) {
echo $host_address;
}
```

### Reports

#### Printed Report
Expand Down Expand Up @@ -255,8 +276,10 @@ Broadcast Address: 192.168.113.255
Min Host: 192.168.112.1
Max Host: 192.168.113.254
*/
```

// Printing the SubnetCalculator object will print the printable report.
#### Printing - String Representation
```php
print($sub);
/*
192.168.112.203/23 Quads Hex Binary
Expand All @@ -275,6 +298,13 @@ Max Host: 192.168.113.254
*/
```

### Standard Interfaces

#### JsonSerializable
```php
$json = json_encode($sub);
```

Unit Tests
----------

Expand Down
2 changes: 1 addition & 1 deletion coding_standard.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="MathPHP">
<ruleset name="SubnetCalculator">
<description>The coding standard for IPv4\SubnetCalculator.</description>

<rule ref="PSR2">
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"keywords": ["ipv4", "subnet", "calculator", "network", "cidr", "address", "ip"],
"homepage": "https://github.com/markrogoyski/ipv4-subnet-calculator-php",
"require": {
"php": ">=5.3.0"
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"satooshi/php-coveralls": "^1.0",
"squizlabs/php_codesniffer": "2.*"
"phpunit/phpunit": "6.*",
"satooshi/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "2.*",
"phpstan/phpstan": "*",
"phpmd/phpmd": "^2.6",
"phploc/phploc": "*"
},
"autoload": {
"psr-4": { "IPv4\\": "src/" }
Expand All @@ -23,7 +26,7 @@
"name": "Mark Rogoyski",
"email": "mark@rogoyski.com",
"homepage": "https://github.com/markrogoyski",
"role": "Developer"
"role": "Lead Developer"
}
],
"license": "MIT"
Expand Down
Loading

0 comments on commit 20a8c9b

Please sign in to comment.