Skip to content

Commit

Permalink
Merge pull request #151 from gsteel/psalm-baseline-reduction
Browse files Browse the repository at this point in the history
General psalm baseline reduction - Low hanging fruit
  • Loading branch information
Ocramius committed Sep 13, 2022
2 parents b0e8bc7 + a2fbeba commit 115b6f9
Show file tree
Hide file tree
Showing 44 changed files with 200 additions and 575 deletions.
2 changes: 0 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2083,11 +2083,9 @@
<InvalidArgument occurrences="1">
<code>1</code>
</InvalidArgument>
<LessSpecificReturnStatement occurrences="1"/>
<MixedOperand occurrences="1">
<code>$value</code>
</MixedOperand>
<MoreSpecificReturnType occurrences="1"/>
<PossiblyInvalidArgument occurrences="1">
<code>$args</code>
</PossiblyInvalidArgument>
Expand Down
25 changes: 7 additions & 18 deletions test/BetweenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class BetweenTest extends TestCase
{
/**
* @psalm-return array<string, array{
* min: int,
* max: int,
* min: int|string,
* max: int|string,
* inclusive: bool,
* expected: bool,
* value: int|float|string
Expand Down Expand Up @@ -185,12 +185,9 @@ public function providerBasic(): array
* @dataProvider providerBasic
* @param int|float|string $min
* @param int|float|string $max
* @param bool $inclusive
* @param bool $expected
* @param mixed $value
* @return void
*/
public function testBasic($min, $max, $inclusive, $expected, $value)
public function testBasic($min, $max, bool $inclusive, bool $expected, $value): void
{
$validator = new Between(['min' => $min, 'max' => $max, 'inclusive' => $inclusive]);

Expand All @@ -203,43 +200,35 @@ public function testBasic($min, $max, $inclusive, $expected, $value)

/**
* Ensures that getMessages() returns expected default value
*
* @return void
*/
public function testGetMessages()
public function testGetMessages(): void
{
$validator = new Between(['min' => 1, 'max' => 10]);
$this->assertEquals([], $validator->getMessages());
}

/**
* Ensures that getMin() returns expected value
*
* @return void
*/
public function testGetMin()
public function testGetMin(): void
{
$validator = new Between(['min' => 1, 'max' => 10]);
$this->assertEquals(1, $validator->getMin());
}

/**
* Ensures that getMax() returns expected value
*
* @return void
*/
public function testGetMax()
public function testGetMax(): void
{
$validator = new Between(['min' => 1, 'max' => 10]);
$this->assertEquals(10, $validator->getMax());
}

/**
* Ensures that getInclusive() returns expected default value
*
* @return void
*/
public function testGetInclusive()
public function testGetInclusive(): void
{
$validator = new Between(['min' => 1, 'max' => 10]);
$this->assertEquals(true, $validator->getInclusive());
Expand Down
4 changes: 1 addition & 3 deletions test/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ class CallbackTest extends TestCase
{
/**
* Ensures that the validator follows expected behavior
*
* @return void
*/
public function testBasic()
public function testBasic(): void
{
$valid = new Callback([$this, 'objectCallback']);
$this->assertTrue($valid->isValid('test'));
Expand Down
28 changes: 7 additions & 21 deletions test/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,17 @@ public function testBasic(string $input, bool $expected): void

/**
* Ensures that getMessages() returns expected default value
*
* @return void
*/
public function testGetMessages()
public function testGetMessages(): void
{
$validator = new CreditCard();
$this->assertEquals([], $validator->getMessages());
}

/**
* Ensures that get and setType works as expected
*
* @return void
*/
public function testGetSetType()
public function testGetSetType(): void
{
$validator = new CreditCard();
$this->assertCount(12, $validator->getType());
Expand Down Expand Up @@ -120,10 +116,8 @@ public function testProvider(string $input, bool $expected): void

/**
* Test non string input
*
* @return void
*/
public function testIsValidWithNonString()
public function testIsValidWithNonString(): void
{
$validator = new CreditCard(CreditCard::VISA);
$this->assertFalse($validator->isValid(['something']));
Expand Down Expand Up @@ -300,10 +294,8 @@ public function testMirCard($input, $expected): void

/**
* Test an invalid service class
*
* @return void
*/
public function testInvalidServiceClass()
public function testInvalidServiceClass(): void
{
$validator = new CreditCard();
$this->assertEquals(null, $validator->getService());
Expand All @@ -315,10 +307,8 @@ public function testInvalidServiceClass()

/**
* Test a config object
*
* @return void
*/
public function testTraversableObject()
public function testTraversableObject(): void
{
$options = ['type' => 'Visa'];
$config = new ArrayObject($options);
Expand All @@ -329,10 +319,8 @@ public function testTraversableObject()

/**
* Test optional parameters with config object
*
* @return void
*/
public function testOptionalConstructorParameterByTraversableObject()
public function testOptionalConstructorParameterByTraversableObject(): void
{
$config = new ArrayObject(
['type' => 'Visa', 'service' => [self::class, 'staticCallback']]
Expand All @@ -345,10 +333,8 @@ public function testOptionalConstructorParameterByTraversableObject()

/**
* Test optional constructor parameters
*
* @return void
*/
public function testOptionalConstructorParameter()
public function testOptionalConstructorParameter(): void
{
$validator = new CreditCard('Visa', [self::class, 'staticCallback']);
$this->assertEquals(['Visa'], $validator->getType());
Expand Down
36 changes: 9 additions & 27 deletions test/Db/NoRecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,26 @@ protected function getMockNoResult()

/**
* Test basic function of RecordExists (no exclusion)
*
* @return void
*/
public function testBasicFindsRecord()
public function testBasicFindsRecord(): void
{
$validator = new NoRecordExists('users', 'field1', null, $this->getMockHasResult());
$this->assertFalse($validator->isValid('value1'));
}

/**
* Test basic function of RecordExists (no exclusion)
*
* @return void
*/
public function testBasicFindsNoRecord()
public function testBasicFindsNoRecord(): void
{
$validator = new NoRecordExists('users', 'field1', null, $this->getMockNoResult());
$this->assertTrue($validator->isValid('nosuchvalue'));
}

/**
* Test the exclusion function
*
* @return void
*/
public function testExcludeWithArray()
public function testExcludeWithArray(): void
{
$validator = new NoRecordExists(
'users',
Expand All @@ -144,10 +138,8 @@ public function testExcludeWithArray()
/**
* Test the exclusion function
* with an array
*
* @return void
*/
public function testExcludeWithArrayNoRecord()
public function testExcludeWithArrayNoRecord(): void
{
$validator = new NoRecordExists(
'users',
Expand All @@ -161,10 +153,8 @@ public function testExcludeWithArrayNoRecord()
/**
* Test the exclusion function
* with a string
*
* @return void
*/
public function testExcludeWithString()
public function testExcludeWithString(): void
{
$validator = new NoRecordExists('users', 'field1', 'id != 1', $this->getMockHasResult());
$this->assertFalse($validator->isValid('value3'));
Expand All @@ -173,10 +163,8 @@ public function testExcludeWithString()
/**
* Test the exclusion function
* with a string
*
* @return void
*/
public function testExcludeWithStringNoRecord()
public function testExcludeWithStringNoRecord(): void
{
$validator = new NoRecordExists('users', 'field1', 'id != 1', $this->getMockNoResult());
$this->assertTrue($validator->isValid('nosuchvalue'));
Expand All @@ -185,10 +173,8 @@ public function testExcludeWithStringNoRecord()
/**
* Test that the class throws an exception if no adapter is provided
* and no default is set.
*
* @return void
*/
public function testThrowsExceptionWithNoAdapter()
public function testThrowsExceptionWithNoAdapter(): void
{
$validator = new NoRecordExists('users', 'field1', 'id != 1');
$this->expectException(RuntimeException::class);
Expand All @@ -198,10 +184,8 @@ public function testThrowsExceptionWithNoAdapter()

/**
* Test that schemas are supported and run without error
*
* @return void
*/
public function testWithSchema()
public function testWithSchema(): void
{
$validator = new NoRecordExists([
'table' => 'users',
Expand All @@ -212,10 +196,8 @@ public function testWithSchema()

/**
* Test that schemas are supported and run without error
*
* @return void
*/
public function testWithSchemaNoResult()
public function testWithSchemaNoResult(): void
{
$validator = new NoRecordExists([
'table' => 'users',
Expand Down
32 changes: 8 additions & 24 deletions test/Db/RecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ protected function getMockNoResult()

/**
* Test basic function of RecordExists (no exclusion)
*
* @return void
*/
public function testBasicFindsRecord()
public function testBasicFindsRecord(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand All @@ -124,10 +122,8 @@ public function testBasicFindsRecord()

/**
* Test basic function of RecordExists (no exclusion)
*
* @return void
*/
public function testBasicFindsNoRecord()
public function testBasicFindsNoRecord(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand All @@ -139,10 +135,8 @@ public function testBasicFindsNoRecord()

/**
* Test the exclusion function
*
* @return void
*/
public function testExcludeWithArray()
public function testExcludeWithArray(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand All @@ -159,10 +153,8 @@ public function testExcludeWithArray()
/**
* Test the exclusion function
* with an array
*
* @return void
*/
public function testExcludeWithArrayNoRecord()
public function testExcludeWithArrayNoRecord(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand All @@ -179,10 +171,8 @@ public function testExcludeWithArrayNoRecord()
/**
* Test the exclusion function
* with a string
*
* @return void
*/
public function testExcludeWithString()
public function testExcludeWithString(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand All @@ -196,10 +186,8 @@ public function testExcludeWithString()
/**
* Test the exclusion function
* with a string
*
* @return void
*/
public function testExcludeWithStringNoRecord()
public function testExcludeWithStringNoRecord(): void
{
$validator = new RecordExists('users', 'field1', 'id != 1', $this->getMockNoResult());
$this->assertFalse($validator->isValid('nosuchvalue'));
Expand All @@ -217,10 +205,8 @@ public function testExcludeConstructor(): void
/**
* Test that the class throws an exception if no adapter is provided
* and no default is set.
*
* @return void
*/
public function testThrowsExceptionWithNoAdapter()
public function testThrowsExceptionWithNoAdapter(): void
{
$validator = new RecordExists('users', 'field1', 'id != 1');
$this->expectException(RuntimeException::class);
Expand All @@ -230,10 +216,8 @@ public function testThrowsExceptionWithNoAdapter()

/**
* Test that schemas are supported and run without error
*
* @return void
*/
public function testWithSchema()
public function testWithSchema(): void
{
$validator = new RecordExists([
'table' => 'users',
Expand Down
Loading

0 comments on commit 115b6f9

Please sign in to comment.