Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  update actions
  bump psalm minimum version
  hide the password to prevent it being accidently displayed
  fix psalm errors
  CS
  • Loading branch information
Baptouuuu committed Oct 19, 2024
2 parents 077dccf + e7f16ae commit 560d67b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 31 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
name: 'Tests'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- 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"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover --exclude-group=fixtures
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fixtures:
Expand All @@ -39,20 +39,20 @@ jobs:
name: 'Fixtures'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- 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"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover --group=fixtures
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
psalm:
Expand All @@ -64,14 +64,14 @@ jobs:
name: 'Psalm'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: Psalm
Expand All @@ -84,13 +84,13 @@ jobs:
name: 'CS'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
- name: CS
run: vendor/bin/php-cs-fixer fix --diff --dry-run
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.3.1 - 2024-10-19

### Changed

- `Innmind\Url\Authority\UserInformation\Password` inner value is now stored inside a `\SensitiveParameterValue` to prevent a password being accidently displayed in a dump/log.

## 4.3.0 - 2023-09-16

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"phpunit/phpunit": "~10.2",
"vimeo/psalm": "~5.13",
"vimeo/psalm": "~5.26",
"innmind/black-box": "~5.0",
"innmind/coding-standard": "~2.0"
},
Expand Down
6 changes: 3 additions & 3 deletions src/Authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public static function of(
public static function none(): self
{
return new self(
Authority\UserInformation::none(),
Authority\Host::none(),
Authority\Port::none(),
UserInformation::none(),
Host::none(),
Port::none(),
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Authority/Port.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public function format(): string

public function value(): int
{
return $this->value ?: 0;
return match ($this->value) {
null => 0,
default => $this->value,
};
}

public function toString(): string
Expand Down
13 changes: 7 additions & 6 deletions src/Authority/UserInformation/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
final class Password
{
private const PATTERN = '/^[\pL\pN-]+$/';
private string $value;
/** @var \SensitiveParameterValue<string> */
private \SensitiveParameterValue $value;

private function __construct(string $value)
{
$this->value = $value;
$this->value = new \SensitiveParameterValue($value);
}

/**
Expand All @@ -44,24 +45,24 @@ public static function none(): self

public function equals(self $password): bool
{
return $this->value === $password->value;
return $this->value->getValue() === $password->value->getValue();
}

public function format(User $user): string
{
if ($this->value === '') {
if ($this->value->getValue() === '') {
return $user->toString();
}

if ($user->toString() === '') {
throw new PasswordCannotBeSpecifiedWithoutAUser;
}

return $user->toString().':'.$this->value;
return $user->toString().':'.(string) $this->value->getValue();
}

public function toString(): string
{
return $this->value;
return $this->value->getValue();
}
}
40 changes: 32 additions & 8 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,42 @@ public static function of(string $string): self
}

return new self(
$data['scheme'] ? Scheme::of($data['scheme']) : Scheme::none(),
match ($data['scheme']) {
null, '' => Scheme::none(),
default => Scheme::of($data['scheme']),
},
Authority::of(
UserInformation::of(
$data['user'] ? User::of($data['user']) : User::none(),
$data['pass'] ? Password::of($data['pass']) : Password::none(),
match ($data['user']) {
null, '' => User::none(),
default => User::of($data['user']),
},
match ($data['pass']) {
null, '' => Password::none(),
default => Password::of($data['pass']),
},
),
$data['host'] ? Host::of($data['host']) : Host::none(),
$data['port'] ? Port::of((int) $data['port']) : Port::none(),
match ($data['host']) {
null, '' => Host::none(),
default => Host::of($data['host']),
},
match ($data['port']) {
null, '' => Port::none(),
default => Port::of((int) $data['port']),
},
),
$data['path'] && !empty($data['path']) ? Path::of($data['path']) : Path::none(),
$data['query'] ? Query::of($data['query']) : Query::none(),
$data['fragment'] ? Fragment::of($data['fragment']) : Fragment::none(),
match ($data['path']) {
null, '' => Path::none(),
default => Path::of($data['path']),
},
match ($data['query']) {
null, '' => Query::none(),
default => Query::of($data['query']),
},
match ($data['fragment']) {
null, '' => Fragment::none(),
default => Fragment::of($data['fragment']),
},
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AuthorityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function testEquals()
{
$this
->forAll(Fixture::any(), Fixture::any())
->filter(fn($a, $b) => $a->toString() !== $b->toString())
->filter(static fn($a, $b) => $a->toString() !== $b->toString())
->then(function($a, $b) {
$this->assertTrue($a->equals($a));
$this->assertTrue(
Expand Down
2 changes: 1 addition & 1 deletion tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function testEquals()
{
$this
->forAll(Fixture::any(), Fixture::any())
->filter(fn($a, $b) => $a->toString() !== $b->toString())
->filter(static fn($a, $b) => $a->toString() !== $b->toString())
->then(function($a, $b) {
$this->assertTrue($a->equals($a));
$this->assertTrue($a->equals(new Url(
Expand Down

0 comments on commit 560d67b

Please sign in to comment.