Skip to content

Commit 019c0dc

Browse files
committed
Aplicando princípio Single Responsability
1 parent 2fcef66 commit 019c0dc

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Algumas delas são:
4747
> nunca deve abrir uma classe e adicionar um novo recurso, você deverá estendê-la (Expansão e Fechado para alteração)
4848
4949
- L: Liskov Substituition - As classes derivadas devem ser substituíveis por suas classes base, sem que resultem em erros.
50-
> subtipos e tipo devem se complementar
50+
> subtipos e tipo(pais e filhos) devem se complementar
5151
5252
- I: Interface Segregation - Muitas interfaces específicas são melhores do que uma interface única.
5353
> sempre trabalhar com interface

src/Attributes.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Solid\Html;
4+
5+
class Attributes
6+
{
7+
private $attributes;
8+
9+
public function __construct(array $attributes)
10+
{
11+
$this->attributes = $attributes;
12+
}
13+
14+
public function __toString() : string
15+
{
16+
$result = [];
17+
18+
foreach ($this->attributes as $key => $value)
19+
{
20+
$result[] = $key . '="' . $value . '"';
21+
}
22+
23+
return ' ' . implode(' ' , $result);
24+
}
25+
}

src/Tags.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Solid\Html;
4+
5+
class Tags
6+
{
7+
public function img(string $src)
8+
{
9+
return '<img src="' . $src . '">';
10+
}
11+
12+
public function a(string $href , string $anchor)
13+
{
14+
return '<a href="' . $href . '">' . $anchor . '</a>';
15+
}
16+
}

tests/AttributesTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Solid\Html;
4+
5+
class AttributesTest extends \PHPUnit\Framework\TestCase
6+
{
7+
8+
public function testCriarAtributosHtmlParaTags()
9+
{
10+
$attributes = new Attributes([
11+
"class" => "btn btn-default",
12+
"data-modal" => "#login",
13+
"id" => "login"
14+
]
15+
);
16+
17+
$this->assertEquals(' class="btn btn-default" data-modal="#login" id="login"' , $attributes);
18+
}
19+
20+
}

tests/TagsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Solid\Html;
4+
5+
class TagsTest extends \PHPUnit\Framework\TestCase
6+
{
7+
public function testCriarTagImgComSrc()
8+
{
9+
$html = new Html;
10+
$img = $html->img('img/photo.png');
11+
12+
$this->assertEquals('<img src="img/photo.png">', $img);
13+
}
14+
15+
public function testCriarTagAComImgAncora()
16+
{
17+
$html = new Html;
18+
$img = $html->img('img/photo.png');
19+
20+
$a = $html->a('http://www.example.com.br', $img);
21+
22+
$this->assertEquals('<a href="http://www.example.com.br"><img src="img/photo.png"></a>', $a);
23+
}
24+
}

0 commit comments

Comments
 (0)