Skip to content
Merged
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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
70 changes: 7 additions & 63 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,12 @@ name: CI
on: [push, pull_request]

jobs:
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
- name: Composer
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
blackbox:
uses: innmind/github-workflows/.github/workflows/black-box-matrix.yml@main
coverage:
uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main
secrets: inherit
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'Psalm'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: Psalm
run: vendor/bin/psalm --shepherd
uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main
cs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v2"
- name: CS
run: vendor/bin/php-cs-fixer fix --diff --dry-run
uses: innmind/github-workflows/.github/workflows/cs.yml@main
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Create release

on:
push:
tags:
- '*'

jobs:
release:
uses: innmind/github-workflows/.github/workflows/release.yml@main
secrets: inherit
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [Unreleased]

### Added

- `Innmind\IP\IPv4::attempt()`
- `Innmind\IP\IPv6::attempt()`

### Changed

- Require PHP `8.4`

### Removed

- `Innmind\IP\Exception\Exception`
- `Innmind\IP\Exception\DomainException`

## 3.2.0 - 2023-09-16

### Added
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IP

[![Build Status](https://github.com/innmind/IP/workflows/CI/badge.svg?branch=master)](https://github.com/innmind/IP/actions?query=workflow%3ACI)
[![CI](https://github.com/Innmind/IP/actions/workflows/ci.yml/badge.svg)](https://github.com/Innmind/IP/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/innmind/IP/branch/develop/graph/badge.svg)](https://codecov.io/gh/innmind/IP)
[![Type Coverage](https://shepherd.dev/github/innmind/IP/coverage.svg)](https://shepherd.dev/github/innmind/IP)

Expand All @@ -19,9 +19,11 @@ use Innmind\IP\{
IP,
IPv4,
IPv6,
Exception\DomainException,
};
use Innmind\Immutable\Maybe;
use Innmind\Immutable\{
Maybe,
Attempt,
};

$ipv4 = IP::v4('192.168.0.1');
$ipv6 = IP::v6('2001:db8:a0b:12f0::1');
Expand All @@ -31,4 +33,6 @@ IPv4::of('localhost'); // throws DomainException
IPv6::of('localhost'); // throws DomainException
IPv4::maybe('localhost'); // returns Maybe<IPv4>
IPv6::maybe('localhost'); // returns Maybe<IPv6>
IPv4::attempt('localhost'); // returns Attempt<IPv4>
IPv6::attempt('localhost'); // returns Attempt<IPv6>
```
27 changes: 27 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types = 1);

require 'vendor/autoload.php';

use Innmind\BlackBox\{
Application,
PHPUnit\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->when(
\getenv('ENABLE_COVERAGE') !== false,
static fn(Application $app) => $app
->scenariiPerProof(1)
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
__DIR__.'/tests/',
)
->dumpTo('coverage.clover')
->enableWhen(true),
),
)
->tryToProve(Load::directory(__DIR__.'/tests/'))
->exit();
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"issues": "http://github.com/Innmind/IP/issues"
},
"require": {
"php": "~8.2",
"innmind/immutable": "~4.1|~5.0"
"php": "~8.4",
"innmind/immutable": "~6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -29,8 +29,8 @@
}
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~5.6",
"innmind/static-analysis": "~1.3",
"innmind/black-box": "~6.5",
"innmind/coding-standard": "~2.0"
}
}
17 changes: 0 additions & 17 deletions phpunit.xml.dist

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/DomainException.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/Exception.php

This file was deleted.

6 changes: 2 additions & 4 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Innmind\IP;

use Innmind\IP\Exception\DomainException;

/**
* @psalm-immutable
*/
Expand All @@ -27,7 +25,7 @@ final private function __construct(string $address)
final public static function v4(string $address): IPv4
{
if (!\filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
throw new DomainException($address);
throw new \DomainException($address);
}

/** @psalm-suppress ArgumentTypeCoercion $address cannot be empty here */
Expand All @@ -40,7 +38,7 @@ final public static function v4(string $address): IPv4
final public static function v6(string $address): IPv6
{
if (!\filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
throw new DomainException($address);
throw new \DomainException($address);
}

/** @psalm-suppress ArgumentTypeCoercion $address cannot be empty here */
Expand Down
23 changes: 15 additions & 8 deletions src/IPv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace Innmind\IP;

use Innmind\IP\Exception\DomainException;
use Innmind\Immutable\Maybe;
use Innmind\Immutable\{
Maybe,
Attempt,
};

/**
* @psalm-immutable
Expand Down Expand Up @@ -34,11 +36,16 @@ public static function localhost(): self
*/
public static function maybe(string $address): Maybe
{
try {
return Maybe::just(self::of($address));
} catch (DomainException $e) {
/** @var Maybe<self> */
return Maybe::nothing();
}
return self::attempt($address)->maybe();
}

/**
* @psalm-pure
*
* @return Attempt<self>
*/
public static function attempt(string $address): Attempt
{
return Attempt::of(static fn() => self::of($address));
}
}
23 changes: 15 additions & 8 deletions src/IPv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace Innmind\IP;

use Innmind\IP\Exception\DomainException;
use Innmind\Immutable\Maybe;
use Innmind\Immutable\{
Maybe,
Attempt,
};

/**
* @psalm-immutable
Expand Down Expand Up @@ -34,11 +36,16 @@ public static function localhost(): self
*/
public static function maybe(string $address): Maybe
{
try {
return Maybe::just(self::of($address));
} catch (DomainException $e) {
/** @var Maybe<self> */
return Maybe::nothing();
}
return self::attempt($address)->maybe();
}

/**
* @psalm-pure
*
* @return Attempt<self>
*/
public static function attempt(string $address): Attempt
{
return Attempt::of(static fn() => self::of($address));
}
}
14 changes: 6 additions & 8 deletions tests/IPv4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
use Innmind\IP\{
IPv4,
IP,
Exception\DomainException,
};
use PHPUnit\Framework\TestCase;
use Innmind\BlackBox\PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class IPv4Test extends TestCase
{
/**
* @dataProvider addresses
*/
#[DataProvider('addresses')]
public function testInterface($address)
{
$this->assertInstanceOf(IP::class, IPv4::of($address));
Expand Down Expand Up @@ -42,15 +40,15 @@ public function testLocalhost()

public function testThrowWhenInvalidFormat()
{
$this->expectException(DomainException::class);
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('localhost');

IPv4::of('localhost');
}

public function testThrowWhenOutOfBound()
{
$this->expectException(DomainException::class);
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('256.0.0.1');

IPv4::of('256.0.0.1');
Expand All @@ -64,7 +62,7 @@ public function testMaybeReturnNothingForInvalidAddress()
));
}

public function addresses(): array
public static function addresses(): array
{
return [
['0.0.0.0'],
Expand Down
Loading