Skip to content

Commit 3b7eb29

Browse files
author
Dominik Liebler
committed
cs AbstractFactory
1 parent 8c520c3 commit 3b7eb29

15 files changed

+39
-52
lines changed

AbstractFactory/AbstractFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ abstract class AbstractFactory
2828
* Creates a text component
2929
*
3030
* @param string $content
31+
*
3132
* @return Text
3233
*/
3334
abstract public function createText($content);
@@ -37,6 +38,7 @@ abstract public function createText($content);
3738
*
3839
* @param string $path
3940
* @param string $name
41+
*
4042
* @return Picture
4143
*/
4244
abstract public function createPicture($path, $name = '');

AbstractFactory/Html/Picture.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
*/
1212
class Picture extends BasePicture
1313
{
14-
1514
/**
1615
* some crude rendering from HTML output
1716
*
1817
* @return string
1918
*/
2019
public function render()
2120
{
22-
return sprintf('<img src="%s" title="$s"/>', $this->_path, $this->_name);
21+
return sprintf('<img src="%s" title="$s"/>', $this->path, $this->name);
2322
}
24-
2523
}

AbstractFactory/Html/Text.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
*/
1212
class Text extends BaseText
1313
{
14-
1514
/**
1615
* some crude rendering from HTML output
1716
*
1817
* @return string
1918
*/
2019
public function render()
2120
{
22-
return '<div>' . htmlspecialchars($this->_text) . '</div>';
21+
return '<div>' . htmlspecialchars($this->text) . '</div>';
2322
}
24-
2523
}

AbstractFactory/HtmlFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
*/
1010
class HtmlFactory extends AbstractFactory
1111
{
12-
1312
/**
1413
* Creates a picture component
1514
*
1615
* @param string $path
1716
* @param string $name
17+
*
1818
* @return Html\Picture|Picture
1919
*/
2020
public function createPicture($path, $name = '')
@@ -26,11 +26,11 @@ public function createPicture($path, $name = '')
2626
* Creates a text component
2727
*
2828
* @param string $content
29+
*
2930
* @return Html\Text|Text
3031
*/
3132
public function createText($content)
3233
{
3334
return new Html\Text($content);
3435
}
35-
3636
}

AbstractFactory/Json/Picture.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
*/
1212
class Picture extends BasePicture
1313
{
14-
1514
/**
1615
* some crude rendering from JSON output
1716
*
1817
* @return string
1918
*/
2019
public function render()
2120
{
22-
return json_encode(array('title' => $this->_name, 'path' => $this->_path));
21+
return json_encode(array('title' => $this->name, 'path' => $this->path));
2322
}
24-
2523
}

AbstractFactory/Json/Text.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
*/
1212
class Text extends BaseText
1313
{
14-
1514
/**
1615
* some crude rendering from JSON output
1716
*
1817
* @return string
1918
*/
2019
public function render()
2120
{
22-
return json_encode(array('content' => $this->_text));
21+
return json_encode(array('content' => $this->text));
2322
}
24-
2523
}

AbstractFactory/JsonFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ class JsonFactory extends AbstractFactory
1616
*
1717
* @param string $path
1818
* @param string $name
19+
*
1920
* @return Json\Picture|Picture
2021
*/
2122
public function createPicture($path, $name = '')
2223
{
2324
return new Json\Picture($path, $name);
2425
}
2526

26-
2727
/**
2828
* Creates a text component
2929
*
3030
* @param string $content
31+
*
3132
* @return Json\Text|Text
3233
*/
3334
public function createText($content)
3435
{
3536
return new Json\Text($content);
3637
}
37-
3838
}

AbstractFactory/Media.php renamed to AbstractFactory/MediaInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace DesignPatterns\AbstractFactory;
44

55
/**
6-
* Interface Media
6+
* Interface MediaInterface
77
*
88
* This contract is not part of the pattern, in general case, each component
99
* are not related
1010
*/
11-
interface Media
11+
interface MediaInterface
1212
{
1313

1414
/**

AbstractFactory/Picture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Class Picture
77
*/
8-
abstract class Picture implements Media
8+
abstract class Picture implements MediaInterface
99
{
1010

1111
/**

AbstractFactory/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Class Text
77
*/
8-
abstract class Text implements Media
8+
abstract class Text implements MediaInterface
99
{
1010
/**
1111
* @var string

Adapter/ElecBookAdapter.php renamed to Adapter/EBookAdapter.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
namespace DesignPatterns\Adapter;
88

99
/**
10-
* ElecBookAdapter is an adapter to fit an e-book like a paper book
10+
* EBookAdapter is an adapter to fit an e-book like a paper book
1111
*
1212
* This is the adapter here. Notice it implemennts PaperBookInterface,
1313
* therefore you don't have to change the code of the client which using paper book.
1414
*/
15-
class ElecBookAdapter implements PaperBookInterface
15+
class EBookAdapter implements PaperBookInterface
1616
{
1717

1818
protected $eBook;
1919

2020
/**
2121
* Notice the constructor, it "wraps" an electronic book
22+
*
23+
* @param EBookInterface $ebook
2224
*/
23-
public function __construct(ElecBookInterface $ebook)
25+
public function __construct(EBookInterface $ebook)
2426
{
2527
$this->eBook = $ebook;
2628
}
@@ -33,9 +35,11 @@ public function open()
3335
$this->eBook->pressStart();
3436
}
3537

38+
/**
39+
* turns pages
40+
*/
3641
public function turnPage()
3742
{
3843
$this->eBook->pressNext();
3944
}
40-
41-
}
45+
}

Adapter/EBookInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace DesignPatterns\Adapter;
4+
5+
/**
6+
* EBookInterface is a contract for an electronic book
7+
*/
8+
interface EBookInterface
9+
{
10+
11+
function pressNext();
12+
13+
function pressStart();
14+
}

Adapter/ElecBookInterface.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

Command/Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
interface Command
2727
{
28-
2928
/**
3029
* this is the most important method in the Command pattern,
3130
* The Receiver goes in the constructor.

Tests/AbstractFactory/AbstractFactoryTest.php

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

3-
/*
4-
* DesignPatternPHP
5-
*/
6-
73
namespace DesignPatterns\Tests\AbstractFactory;
84

95
use DesignPatterns\AbstractFactory\AbstractFactory;
@@ -15,7 +11,6 @@
1511
*/
1612
class AbstractFactoryTest extends \PHPUnit_Framework_TestCase
1713
{
18-
1914
public function getFactories()
2015
{
2116
return array(
@@ -39,12 +34,11 @@ public function testComponentCreation(AbstractFactory $factory)
3934
$factory->createText('footnotes')
4035
);
4136

42-
$this->assertContainsOnly('DesignPatterns\AbstractFactory\Media', $article);
37+
$this->assertContainsOnly('DesignPatterns\AbstractFactory\MediaInterface', $article);
38+
4339
/* this is the time to look at the Builder pattern. This pattern
4440
* helps you to create complex object like that article above with
4541
* a given Abstract Factory
4642
*/
47-
4843
}
49-
5044
}

0 commit comments

Comments
 (0)