Skip to content

Commit

Permalink
More strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Apr 17, 2023
1 parent 06139b8 commit aeafe2e
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 54 deletions.
4 changes: 1 addition & 3 deletions src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class ConnectionManager

/**
* The events to register listeners for during initialization.
*
* @var array
*/
protected $listen = [
protected array $listen = [
'LdapRecord\Auth\Events\*',
'LdapRecord\Query\Events\*',
'LdapRecord\Models\Events\*',
Expand Down
4 changes: 1 addition & 3 deletions src/Events/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class Logger
{
/**
* The logger instance.
*
* @var LoggerInterface|null
*/
protected $logger;
protected ?LoggerInterface $logger;

/**
* Constructor.
Expand Down
14 changes: 4 additions & 10 deletions src/Models/Attributes/Guid.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ class Guid
{
/**
* The string GUID value.
*
* @var string
*/
protected $value;
protected ?string $value = null;

/**
* The guid structure in order by section to parse using substr().
*
* @author Chad Sikorra <Chad.Sikorra@gmail.com>
*
* @see https://github.com/ldaptools/ldaptools
*
* @var array
*/
protected $guidSections = [
protected array $guidSections = [
[[-26, 2], [-28, 2], [-30, 2], [-32, 2]],
[[-22, 2], [-24, 2]],
[[-18, 2], [-20, 2]],
Expand All @@ -36,10 +32,8 @@ class Guid
* @author Chad Sikorra <Chad.Sikorra@gmail.com>
*
* @see https://github.com/ldaptools/ldaptools
*
* @var array
*/
protected $octetSections = [
protected array $octetSections = [
[6, 4, 2, 0],
[10, 8],
[14, 12],
Expand All @@ -59,7 +53,7 @@ public static function isValid(string $guid): bool
*
* @throws InvalidArgumentException
*/
public function __construct($value)
public function __construct(string $value)
{
if (static::isValid($value)) {
$this->value = $value;
Expand Down
8 changes: 2 additions & 6 deletions src/Models/OpenLDAP/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ class User extends Entry implements Authenticatable

/**
* The password's attribute name.
*
* @var string
*/
protected $passwordAttribute = 'userpassword';
protected string $passwordAttribute = 'userpassword';

/**
* The password's hash method.
*
* @var string
*/
protected $passwordHashMethod = 'ssha';
protected string $passwordHashMethod = 'ssha';

/**
* The object classes of the LDAP model.
Expand Down
5 changes: 2 additions & 3 deletions tests/Integration/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

class GroupTest extends TestCase
{
/** @var OrganizationalUnit */
protected $ou;
protected OrganizationalUnit $ou;

protected function setUp(): void
{
Expand All @@ -33,7 +32,7 @@ protected function tearDown(): void
parent::tearDown();
}

protected function createGroup(array $attributes = [])
protected function createGroup(array $attributes = []): Group
{
$group = (new Group)
->inside($this->ou)
Expand Down
5 changes: 2 additions & 3 deletions tests/Integration/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class UserTest extends TestCase
{
/** @var OrganizationalUnit */
protected $ou;
protected OrganizationalUnit $ou;

protected function setUp(): void
{
Expand All @@ -36,7 +35,7 @@ protected function tearDown(): void
parent::tearDown();
}

protected function createUser(array $attributes = [])
protected function createUser(array $attributes = []): User
{
$user = (new User)
->inside($this->ou)
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Events/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ExampleEvent

class ExampleListener
{
public function handle(SomeEventInterface $event)
public function handle(SomeEventInterface $event): void
{
$_SERVER['__event.test2'] = 'baar';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/Attributes/EscapeValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

class EscapeValueTest extends TestCase
{
protected $escapedDnCharacters = ['\\', ',', '=', '+', '<', '>', ';', '"', '#'];
protected array $escapedDnCharacters = ['\\', ',', '=', '+', '<', '>', ';', '"', '#'];

protected $escapedFilterCharacters = ['\\', '*', '(', ')', "\x00"];
protected array $escapedFilterCharacters = ['\\', '*', '(', ')', "\x00"];

public function test_all_characters_are_escaped_by_default()
{
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Models/Attributes/TimestampTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

class TimestampTest extends TestCase
{
protected $unixTimestamp = 1601605329;
protected int $unixTimestamp = 1601605329;

protected $utcLdapTimestamp = '20201002021244Z';
protected string $utcLdapTimestamp = '20201002021244Z';

protected $offsetLdapTimestamp = '20201002021244-0500';
protected string $offsetLdapTimestamp = '20201002021244-0500';

protected $utcWindowsTimestamp = '20201002021618.0Z';
protected string $utcWindowsTimestamp = '20201002021618.0Z';

protected $offsetWindowsTimestamp = '20201002021618.0-0500';
protected string $offsetWindowsTimestamp = '20201002021618.0-0500';

protected $windowsIntegerTime = '132460789290000000';
protected string $windowsIntegerTime = '132460789290000000';

public function test_exception_is_thrown_when_invalid_type_given()
{
Expand Down
12 changes: 7 additions & 5 deletions tests/Unit/Models/ModelAccessorMutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ class ModelAccessorStub extends Model
'foo-bar' => ['baz'],
];

public function getFooAttribute($bar)
public function getFooAttribute($bar): string
{
return $bar[0].'baz';
}

public function getFooBarAttribute($baz)
public function getFooBarAttribute($baz): ?string
{
if ($baz) {
return $baz[0].'-other';
}

return null;
}

public function getZaxAttribute($value)
public function getZaxAttribute($value): string
{
return 'zax';
}
Expand All @@ -197,12 +199,12 @@ class ModelMutatorStub extends Model
'foo-bar' => ['baz'],
];

public function setFooAttribute($bar)
public function setFooAttribute($bar): void
{
$this->attributes['foo'] = [$bar.'baz'];
}

public function setFooBarAttribute($baz)
public function setFooBarAttribute($baz): void
{
$this->attributes['foo-bar'] = [$baz.'-other'];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/ModelAttributeAppendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class ModelAttributeAppendsTestStub extends Model
{
protected array $appends = ['foo'];

public function getFooAttribute()
public function getFooAttribute(): string
{
return 'bar';
}

public function getFooBarAttribute()
public function getFooBarAttribute(): string
{
return 'foo-bar';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/ModelHasManyInTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function test_get_with_alternate_foreign_key()

class ModelHasManyInStub extends Model
{
public function relation($mockBuilder = null, $foreignKey = 'dn')
public function relation($mockBuilder = null, $foreignKey = 'dn'): HasManyIn
{
$mockBuilder = $mockBuilder ?: m::mock(Builder::class);
$mockBuilder->shouldReceive('clearFilters')->once()->withNoArgs()->andReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/ModelHasManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function test_only_related_with_no_relation_object_classes()
);
}

protected function getRelation()
protected function getRelation(): HasMany
{
$mockBuilder = m::mock(Builder::class);
$mockBuilder->shouldReceive('clearFilters')->once()->withNoArgs()->andReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/ModelHasManyUsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function test_detach()
$this->assertEquals($relation->detach('bar'), 'bar');
}

protected function getRelation()
protected function getRelation(): HasMany
{
$mockBuilder = m::mock(Builder::class);
$mockBuilder->shouldReceive('clearFilters')->once()->withNoArgs()->andReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/ModelHasOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function test_detach()
$this->assertNull($relation->detach());
}

protected function getRelation()
protected function getRelation(): HasOne
{
$mockBuilder = m::mock(Builder::class);
$mockBuilder->shouldReceive('clearFilters')->once()->withNoArgs()->andReturnSelf();
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/ModelRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function test_related_models_are_determined_with_out_of_order_object_clas

class RelationTestStub extends Relation
{
protected $results = [];
protected array $results = [];

public function getResults(): Collection
{
Expand All @@ -260,7 +260,7 @@ public function getResults(): Collection
);
}

public function setResults($results)
public function setResults($results): static
{
$this->results = $results;

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,12 @@ class ModelWithDatesStub extends Model

class ModelBootingTestStub extends Model
{
public static function isBooted()
public static function isBooted(): bool
{
return array_key_exists(static::class, static::booted());
}

public static function booted()
public static function booted(): array
{
return static::$booted;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class BuilderTest extends TestCase
{
protected function newBuilder()
protected function newBuilder(): Builder
{
return new Builder(new Connection([], new LdapFake()));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Query/Model/ActiveDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class ActiveDirectoryTest extends TestCase
{
protected function newBuilder()
protected function newBuilder(): ActiveDirectoryBuilder
{
return (new ActiveDirectoryBuilder(new Connection([], new LdapFake())))->setModel(new Entry());
}
Expand Down

0 comments on commit aeafe2e

Please sign in to comment.