Skip to content

Commit e8ca746

Browse files
author
irishdan
committed
Refactor and fix tests
1 parent de18ce6 commit e8ca746

23 files changed

+93
-66
lines changed

CoordinateLengthCalculator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace IrishDan\ResponsiveImageBundle;
4+
5+
6+
trait CoordinateLengthCalculator
7+
{
8+
/**
9+
* Gets vertical or horizontal length between two coordinates (x, y, x2, y2).
10+
*
11+
* @param string $type
12+
* @param array $coords
13+
* @return mixed
14+
*/
15+
public function getLength($type = 'x', array $coords)
16+
{
17+
$type = strtolower($type);
18+
if ($type == 'x') {
19+
return $coords[2] - $coords[0];
20+
} else {
21+
return $coords[3] - $coords[1];
22+
}
23+
}
24+
}

Event/ImageEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace IrishDan\ResponsiveImageBundle\Event;
44

55

6-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageInterface;
6+
use IrishDan\ResponsiveImageBundle\ResponsiveImageInterface;
77
use Symfony\Component\EventDispatcher\Event;
88

99
/**

Utils/FileManager.php renamed to FileManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
use Symfony\Component\Filesystem\Filesystem;
66

77
/**
88
* Class FileSystem
99
*
10-
* @package ResponsiveImageBundle\Utils
10+
* @package ResponsiveImageBundle
1111
*/
1212
class FileManager
1313
{

Utils/FileToObject.php renamed to FileToObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
use Doctrine\ORM\EntityManager;
66

77
/**
88
* Class FileToObject
99
*
10-
* @package ResponsiveImageBundle\Utils
10+
* @package ResponsiveImageBundle
1111
*/
1212
class FileToObject
1313
{

Utils/FocusCropDataCalculator.php renamed to FocusCropDataCalculator.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
class FocusCropDataCalculator
66
{
7+
use CoordinateLengthCalculator;
78
private $cropCoordinates;
89
private $focusCoordinates;
910
private $styleWidth;
@@ -220,21 +221,4 @@ protected function isInBounds($point, $cropLength, $imageLength, $focusNear, $fo
220221

221222
return $inBounds;
222223
}
223-
224-
/**
225-
* Gets vertical or horizontal length between two coordinates (x, y, x2, y2).
226-
*
227-
* @param string $type
228-
* @param array $coords
229-
* @return mixed
230-
*/
231-
protected function getLength($type = 'x', array $coords)
232-
{
233-
$type = strtolower($type);
234-
if ($type == 'x') {
235-
return $coords[2] - $coords[0];
236-
} else {
237-
return $coords[3] - $coords[1];
238-
}
239-
}
240224
}

Form/CropFocusType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace IrishDan\ResponsiveImageBundle\Form;
44

5-
use IrishDan\ResponsiveImageBundle\Utils\StyleManager;
5+
use IrishDan\ResponsiveImageBundle\StyleManager;
66
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
77
use Symfony\Component\Form\FormBuilderInterface;
88
use Symfony\Component\Form\FormInterface;

Utils/ImageMaker.php renamed to ImageMaker.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
use Intervention\Image\ImageManager;
66

77
/**
88
* Class ImageMaker
99
*
10-
* @package ResponsiveImageBundle\Utils
10+
* @package ResponsiveImageBundle
1111
*/
1212
class ImageMaker
1313
{
14+
use CoordinateLengthCalculator;
15+
1416
/**
1517
* @var
1618
*/
@@ -249,4 +251,21 @@ protected function saveImage($destination, $source)
249251

250252
return $fullPath;
251253
}
254+
255+
/**
256+
* Gets vertical or horizontal length between two coordinates (x, y, x2, y2).
257+
*
258+
* @param string $type
259+
* @param array $coords
260+
* @return mixed
261+
*/
262+
protected function getLength($type = 'x', array $coords)
263+
{
264+
$type = strtolower($type);
265+
if ($type == 'x') {
266+
return $coords[2] - $coords[0];
267+
} else {
268+
return $coords[3] - $coords[1];
269+
}
270+
}
252271
}

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Generator is now included
233233

234234
For image objects you can use your own entity, as long as it implements the ResponsiveImageInterface
235235
```
236-
ResponsiveImageBundle\Utils\ResponsiveImageInterface.
236+
ResponsiveImageBundle\ResponsiveImageInterface.
237237
```
238238
don't for get jquery for the edit widget
239239

Repository/ImageRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace IrishDan\ResponsiveImageBundle\Repository;
44

55
use Doctrine\ORM\EntityRepository;
6-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageRepositoryInterface;
6+
use IrishDan\ResponsiveImageBundle\ResponsiveImageRepositoryInterface;
77

88
class ImageRepository extends EntityRepository implements ResponsiveImageRepositoryInterface
99
{

Resources/config/services.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
services:
22
responsive_image:
3-
class: IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageManager
3+
class: IrishDan\ResponsiveImageBundle\ResponsiveImageManager
44
arguments: [ '@responsive_image.image_maker', '@responsive_image.style_manager', '%responsive_image%', '@responsive_image.file_manager', '@responsive_image.s3_bridge', '@responsive_image.uploader' ]
55

66
responsive_image.file_manager:
7-
class: IrishDan\ResponsiveImageBundle\Utils\FileManager
7+
class: IrishDan\ResponsiveImageBundle\FileManager
88
arguments: ['%kernel.root_dir%', '%responsive_image%', '@filesystem' ]
99

1010
responsive_image.style_manager:
11-
class: IrishDan\ResponsiveImageBundle\Utils\StyleManager
11+
class: IrishDan\ResponsiveImageBundle\StyleManager
1212
arguments: ['@responsive_image.file_manager', '%responsive_image%' ]
1313

1414
responsive_image.image_maker:
15-
class: IrishDan\ResponsiveImageBundle\Utils\ImageMaker
15+
class: IrishDan\ResponsiveImageBundle\ImageMaker
1616
arguments: [ '@responsive_image.file_manager', '%responsive_image%' ]
1717

1818
responsive_image.file_to_object:
19-
class: IrishDan\ResponsiveImageBundle\Utils\FileToObject
19+
class: IrishDan\ResponsiveImageBundle\FileToObject
2020
arguments: [ '@doctrine.orm.entity_manager' ]
2121

2222
responsive_image.uploader:
23-
class: IrishDan\ResponsiveImageBundle\Utils\Uploader
23+
class: IrishDan\ResponsiveImageBundle\Uploader
2424
arguments: ['@responsive_image.file_manager']
2525

2626
responsive_image.s3_bridge:
27-
class: IrishDan\ResponsiveImageBundle\Utils\S3Bridge
27+
class: IrishDan\ResponsiveImageBundle\S3Bridge
2828
arguments: [ '%responsive_image.aws_s3%' ]
2929

3030
# Custom form field type.

Resources/skeleton/entity/Image.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace {{ namespace }}\Entity;
44
55
{% block use_statements %}
6-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageInterface;
6+
use IrishDan\ResponsiveImageBundle\ResponsiveImageInterface;
77
use Symfony\Component\HttpFoundation\File\UploadedFile;
88
use Doctrine\ORM\Mapping as ORM;
99
use Symfony\Component\Validator\Constraints as Assert;

Utils/ResponsiveImageInterface.php renamed to ResponsiveImageInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
use Symfony\Component\HttpFoundation\File\UploadedFile;
66

77
/**
88
* Interface ResponsiveImageInterface
99
*
10-
* @package ResponsiveImageBundle\Utils
10+
* @package ResponsiveImageBundle
1111
*/
1212
Interface ResponsiveImageInterface
1313
{

Utils/ResponsiveImageManager.php renamed to ResponsiveImageManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
/**
66
* Class ResponsiveImageManager
7-
* @package ResponsiveImageBundle\Utils
7+
* @package ResponsiveImageBundle
88
*/
99
class ResponsiveImageManager
1010
{

Utils/ResponsiveImageRepositoryInterface.php renamed to ResponsiveImageRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
Interface ResponsiveImageRepositoryInterface
66
{

Utils/S3Bridge.php renamed to S3Bridge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
use Aws\CommandPool;
66
use Aws\Exception\AwsException;
@@ -9,7 +9,7 @@
99
/**
1010
* Class S3Bridge
1111
*
12-
* @package ResponsiveImageBundle\Utils
12+
* @package ResponsiveImageBundle
1313
*/
1414
class S3Bridge
1515
{

Utils/StyleManager.php renamed to StyleManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Utils;
3+
namespace IrishDan\ResponsiveImageBundle;
44

55
/**
66
* Class StyleManager
77
*
8-
* @package ResponsiveImageBundle\Utils
8+
* @package ResponsiveImageBundle
99
*/
1010
class StyleManager
1111
{
@@ -37,8 +37,8 @@ class StyleManager
3737
/**
3838
* StyleManager constructor.
3939
*
40-
* @param \ResponsiveImageBundle\Utils\FileManager $system
41-
* @param array $parameters
40+
* @param \ResponsiveImageBundle\FileManager $system
41+
* @param array $parameters
4242
*/
4343
public function __construct(FileManager $system, array $parameters)
4444
{
@@ -232,7 +232,7 @@ protected function buildStylePath($styleName, $fileName)
232232
public function setImageStyle(ResponsiveImageInterface $image, $styleName = null)
233233
{
234234
// @TODO: Hack to avoid looping over itself and string paths together.
235-
if ($styleName !== null && !in_array($styleName, $this->styles)) {
235+
if ($styleName !== null && empty($this->getStyle($styleName))) {
236236
return $image;
237237
}
238238

Tests/Entity/TestImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace IrishDan\ResponsiveImageBundle\Tests\Entity;
44

5-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageInterface;
5+
use IrishDan\ResponsiveImageBundle\ResponsiveImageInterface;
66
use Symfony\Component\HttpFoundation\File\UploadedFile;
77
use Doctrine\ORM\Mapping as ORM;
88
use Symfony\Component\Validator\Constraints as Assert;

Tests/Utils/FocusCropDataCalculatorTest.php renamed to Tests/FocusCropDataCalculatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Tests\Utils;
3+
namespace IrishDan\ResponsiveImageBundle\Tests;
44

55
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase;
6-
use IrishDan\ResponsiveImageBundle\Utils\FocusCropDataCalculator;
6+
use IrishDan\ResponsiveImageBundle\FocusCropDataCalculator;
77

88
class FocusCropDataCalculatorTest extends ResponsiveImageTestCase
99
{

Tests/Utils/ImageMakerTest.php renamed to Tests/ImageMakerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Tests\Utils;
3+
namespace IrishDan\ResponsiveImageBundle\Tests;
44

55
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase;
66

77
class ImageMakerTest extends ResponsiveImageTestCase
88
{
99
private $imager;
10-
private $testImagePath = __DIR__ . '/../Resources/dummy.jpg';
11-
private $generatedDirectory = __DIR__ . '/../Resources/generated/';
10+
private $testImagePath = __DIR__ . '/Resources/dummy.jpg';
11+
private $generatedDirectory = __DIR__ . '/Resources/generated/';
1212
private $coordinates = '100, 100, 900, 900:400, 500, 700, 800';
1313

1414
public function setUp()

Tests/Utils/StyleManagerTest.php renamed to Tests/StyleManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Tests\Utils;
3+
namespace IrishDan\ResponsiveImageBundle\Tests;
44

55

66
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase;
77
use IrishDan\ResponsiveImageBundle\Tests\Entity\TestImage;
8-
use IrishDan\ResponsiveImageBundle\Utils\FileManager;
9-
use IrishDan\ResponsiveImageBundle\Utils\FileSystem;
10-
use IrishDan\ResponsiveImageBundle\Utils\StyleManager;
8+
use IrishDan\ResponsiveImageBundle\FileManager;
9+
use IrishDan\ResponsiveImageBundle\FileSystem;
10+
use IrishDan\ResponsiveImageBundle\StyleManager;
1111

1212
class StyleManagerTest extends ResponsiveImageTestCase
1313
{

Tests/Utils/UploaderTest.php renamed to Tests/UploaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace IrishDan\ResponsiveImageBundle\Tests\Utils;
3+
namespace IrishDan\ResponsiveImageBundle\Tests;
44

55
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase;
6-
use IrishDan\ResponsiveImageBundle\Utils\FileSystem;
7-
use IrishDan\ResponsiveImageBundle\Utils\Uploader;
6+
use IrishDan\ResponsiveImageBundle\FileSystem;
7+
use IrishDan\ResponsiveImageBundle\Uploader;
88

99
class UploaderTest extends ResponsiveImageTestCase
1010
{

Twig/ResponsiveImageExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace IrishDan\ResponsiveImageBundle\Twig;
44

55

6-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageInterface;
7-
use IrishDan\ResponsiveImageBundle\Utils\ResponsiveImageManager;
8-
use IrishDan\ResponsiveImageBundle\Utils\StyleManager;
6+
use IrishDan\ResponsiveImageBundle\ResponsiveImageInterface;
7+
use IrishDan\ResponsiveImageBundle\ResponsiveImageManager;
8+
use IrishDan\ResponsiveImageBundle\StyleManager;
99

1010
/**
1111
* Class ResponsiveImageExtension

0 commit comments

Comments
 (0)