Skip to content

Commit

Permalink
use contracts (#61)
Browse files Browse the repository at this point in the history
* use contracts
* update phpstan
  • Loading branch information
ildyria authored Feb 15, 2023
1 parent ed40375 commit 14c624b
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 346 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
"infection/infection": "^0.26.13",
"lychee-org/phpstan-lychee": "dev-master",
"lychee-org/phpstan-lychee": "^1.0.1",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpmd/phpmd": "^2.9",
"phpunit/phpunit": "^9.5.10",
Expand Down Expand Up @@ -85,5 +85,6 @@
"infection/extension-installer": true
}
},
"prefer-stable": true
"prefer-stable": true,
"minimum-stability": "dev"
}
646 changes: 328 additions & 318 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions lib/PHPExif/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPExif\Adapter;

use PHPExif\Mapper\MapperInterface;
use PHPExif\Hydrator\HydratorInterface;
use ForceUTF8\Encoding;
use PHPExif\Contracts\AdapterInterface;
use PHPExif\Contracts\HydratorInterface;
use PHPExif\Contracts\MapperInterface;
use PHPExif\Hydrator\Mutator;

/**
Expand Down Expand Up @@ -39,8 +40,8 @@ public function __construct(array $options = array())
/**
* Mutator for the data mapper
*
* @param \PHPExif\Mapper\MapperInterface $mapper
* @return \PHPExif\Adapter\AdapterInterface
* @param \PHPExif\Contracts\MapperInterface $mapper
* @return \PHPExif\Contracts\AdapterInterface
*/
public function setMapper(MapperInterface $mapper) : AdapterInterface
{
Expand All @@ -52,7 +53,7 @@ public function setMapper(MapperInterface $mapper) : AdapterInterface
/**
* Accessor for the data mapper
*
* @return \PHPExif\Mapper\MapperInterface
* @return \PHPExif\Contracts\MapperInterface
*/
public function getMapper() : MapperInterface
{
Expand All @@ -70,8 +71,8 @@ public function getMapper() : MapperInterface
/**
* Mutator for the hydrator
*
* @param \PHPExif\Hydrator\HydratorInterface $hydrator
* @return \PHPExif\Adapter\AdapterInterface
* @param \PHPExif\Contracts\HydratorInterface $hydrator
* @return \PHPExif\Contracts\AdapterInterface
*/
public function setHydrator(HydratorInterface $hydrator) : AdapterInterface
{
Expand All @@ -83,7 +84,7 @@ public function setHydrator(HydratorInterface $hydrator) : AdapterInterface
/**
* Accessor for the data hydrator
*
* @return \PHPExif\Hydrator\HydratorInterface
* @return \PHPExif\Contracts\HydratorInterface
*/
public function getHydrator() : HydratorInterface
{
Expand All @@ -102,7 +103,7 @@ public function getHydrator() : HydratorInterface
* Set array of options in the current object
*
* @param array $options
* @return \PHPExif\Adapter\AdapterInterface
* @return \PHPExif\Contracts\AdapterInterface
*/
public function setOptions(array $options) : AdapterInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @codeCoverageIgnore
*/

namespace PHPExif\Adapter;
namespace PHPExif\Contracts;

use PHPExif\Exif;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @codeCoverageIgnore
*/

namespace PHPExif\Hydrator;
namespace PHPExif\Contracts;

/**
* PHP Exif Hydrator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @codeCoverageIgnore
*/

namespace PHPExif\Mapper;
namespace PHPExif\Contracts;

/**
* PHP Exif Mapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @codeCoverageIgnore
*/

namespace PHPExif\Reader;
namespace PHPExif\Contracts;

use PHPExif\Exif;

Expand Down
2 changes: 2 additions & 0 deletions lib/PHPExif/Hydrator/Mutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPExif\Hydrator;

use PHPExif\Contracts\HydratorInterface;

/**
* PHP Exif Mutator Hydrator
*
Expand Down
2 changes: 2 additions & 0 deletions lib/PHPExif/Mapper/AbstractMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPExif\Mapper;

use PHPExif\Contracts\MapperInterface;

/**
* PHP Exif Mapper Abstract
*
Expand Down
7 changes: 4 additions & 3 deletions lib/PHPExif/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace PHPExif\Reader;

use PHPExif\Adapter\AdapterInterface;
use PHPExif\Adapter\NoAdapterException;
use PHPExif\Adapter\Exiftool as ExiftoolAdapter;
use PHPExif\Adapter\FFprobe as FFprobeAdapter;
use PHPExif\Adapter\ImageMagick as ImageMagickAdapter;
use PHPExif\Adapter\Native as NativeAdapter;
use PHPExif\Contracts\AdapterInterface;
use PHPExif\Contracts\ReaderInterface;
use PHPExif\Exif;
use PHPExif\Enum\ReaderType;

Expand All @@ -30,7 +31,7 @@ class Reader implements ReaderInterface
/**
* Reader constructor
*
* @param \PHPExif\Adapter\AdapterInterface $adapter
* @param \PHPExif\Contracts\AdapterInterface $adapter
*/
public function __construct(AdapterInterface $adapter)
{
Expand All @@ -40,7 +41,7 @@ public function __construct(AdapterInterface $adapter)
/**
* Getter for the reader adapter
*
* @return \PHPExif\Adapter\AdapterInterface
* @return \PHPExif\Contracts\AdapterInterface
* @throws NoAdapterException When no adapter is set
*/
public function getAdapter(): AdapterInterface
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPExif/Mapper/ExiftoolMapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use PHPExif\Contracts\MapperInterface;

/**
* @covers \PHPExif\Mapper\Exiftool::<!public>
*/
Expand All @@ -16,7 +19,7 @@ public function setUp(): void
*/
public function testClassImplementsCorrectInterface()
{
$this->assertInstanceOf('\\PHPExif\\Mapper\\MapperInterface', $this->mapper);
$this->assertInstanceOf(MapperInterface::class, $this->mapper);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPExif/Mapper/FFprobeMapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use PHPExif\Contracts\MapperInterface;

/**
* @covers \PHPExif\Mapper\FFprobe::<!public>
*/
Expand All @@ -16,7 +19,7 @@ public function setUp(): void
*/
public function testClassImplementsCorrectInterface()
{
$this->assertInstanceOf('\\PHPExif\\Mapper\\MapperInterface', $this->mapper);
$this->assertInstanceOf(MapperInterface::class, $this->mapper);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPExif/Mapper/ImageMagickMapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use PHPExif\Contracts\MapperInterface;

/**
* @covers \PHPExif\Mapper\ImageMagick::<!public>
*/
Expand All @@ -16,7 +19,7 @@ public function setUp(): void
*/
public function testClassImplementsCorrectInterface()
{
$this->assertInstanceOf('\\PHPExif\\Mapper\\MapperInterface', $this->mapper);
$this->assertInstanceOf(MapperInterface::class, $this->mapper);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPExif/Mapper/NativeMapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use PHPExif\Contracts\MapperInterface;

/**
* @covers \PHPExif\Mapper\Native::<!public>
*/
Expand All @@ -16,7 +19,7 @@ public function setUp(): void
*/
public function testClassImplementsCorrectInterface()
{
$this->assertInstanceOf('\\PHPExif\\Mapper\\MapperInterface', $this->mapper);
$this->assertInstanceOf(MapperInterface::class, $this->mapper);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/PHPExif/Reader/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ReaderTest extends \PHPUnit\Framework\TestCase
*/
public function setUp() : void
{
/** @var \PHPExif\Adapter\AdapterInterface */
$adapter = $this->getMockBuilder('\PHPExif\Adapter\AdapterInterface')->getMockForAbstractClass();
/** @var \PHPExif\Contracts\AdapterInterface */
$adapter = $this->getMockBuilder('\PHPExif\Contracts\AdapterInterface')->getMockForAbstractClass();
$this->reader = new \PHPExif\Reader\Reader($adapter);
}

Expand All @@ -29,8 +29,8 @@ public function setUp() : void
*/
public function testConstructorWithAdapter()
{
/** @var \PHPExif\Adapter\AdapterInterface */
$mock = $this->getMockBuilder('\PHPExif\Adapter\AdapterInterface')->getMockForAbstractClass();
/** @var \PHPExif\Contracts\AdapterInterface */
$mock = $this->getMockBuilder('\PHPExif\Contracts\AdapterInterface')->getMockForAbstractClass();
$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Reader', 'adapter');
$reflProperty->setAccessible(true);

Expand All @@ -45,7 +45,7 @@ public function testConstructorWithAdapter()
*/
public function testGetAdapterFromProperty()
{
$mock = $this->getMockBuilder('\PHPExif\Adapter\AdapterInterface')->getMockForAbstractClass();
$mock = $this->getMockBuilder('\PHPExif\Contracts\AdapterInterface')->getMockForAbstractClass();

$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Reader', 'adapter');
$reflProperty->setAccessible(true);
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testGetAdapterThrowsExceptionWhenNoAdapterIsSet()
*/
public function testGetExifPassedToAdapter()
{
$adapter = $this->getMockBuilder('\PHPExif\Adapter\AdapterInterface')->getMockForAbstractClass();
$adapter = $this->getMockBuilder('\PHPExif\Contracts\AdapterInterface')->getMockForAbstractClass();
$adapter->expects($this->once())->method('getExifFromFile');

$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Reader', 'adapter');
Expand Down

0 comments on commit 14c624b

Please sign in to comment.