Skip to content

Commit c5873f1

Browse files
authored
Merge pull request #3 from 8fold/preparing-major
preparing major
2 parents fe9efc4 + 02e7626 commit c5873f1

File tree

6 files changed

+66
-73
lines changed

6 files changed

+66
-73
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
],
1212
"require": {
1313
"php": "^8.0",
14-
"8fold/php-xml-builder": "^0.6"
14+
"8fold/php-xml-builder": "^1.0.0"
1515
},
1616
"require-dev": {
17-
"squizlabs/php_codesniffer": "^3.6.0",
1817
"phpstan/phpstan": "^1.2.0",
19-
"phpunit/phpunit": "^9.5.0"
18+
"phpunit/phpunit": "^9.5",
19+
"squizlabs/php_codesniffer": "^3.6"
2020
},
2121
"autoload": {
2222
"psr-4": {

composer.lock

Lines changed: 39 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<?xml version="1.0"?>
22
<ruleset name="8fold PSR12">
33
<description>PHP-FIG PSR-12 standards with modifications to: control structure (empty space before closing brace).</description>
4+
5+
<file>src</file>
6+
47
<arg name="colors" />
8+
59
<rule ref="PSR12">
610
<!-- 8fold prefers one empty before the closing of control strcuctures
711
in most cases -->
812
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
13+
<!-- We separate `use` clauses, all other PSR12 whitespace rules should apply -->
14+
<exclude name="PSR12.Files.FileHeader"/>
915
</rule>
1016
<rule ref="Generic.Files.LineLength">
1117
<properties>
12-
<property phpcs-only="true" name="lineLimit" value="90"/>
18+
<property phpcs-only="true" name="lineLimit" value="100"/>
1319
<property phpcbf-only="true" name="lineLimit" value="120"/>
1420
</properties>
1521
</rule>

src/Document.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44

55
namespace Eightfold\HTMLBuilder;
66

7+
use Stringable;
8+
79
use Eightfold\XMLBuilder\Comment;
810
use Eightfold\XMLBuilder\Contracts\Buildable;
911
use Eightfold\HTMLBuilder\Element;
1012

1113
class Document implements Buildable
1214
{
13-
private string $title = '';
14-
private string $lang = 'en';
15-
private string $charset = 'utf-8';
16-
1715
/**
18-
* @var array<Element|Comment>
16+
* @var array<string|Stringable>
1917
*/
2018
private array $head = [];
2119

2220
/**
23-
* @var array<Element|Comment|string>
21+
* @var array<string|Stringable>
2422
*/
2523
private array $body = [];
2624

@@ -32,31 +30,20 @@ public static function create(
3230
return new static($title, $lang, $charset);
3331
}
3432

35-
final public function __construct(
36-
string $title,
37-
string $lang = 'en',
38-
string $charset = 'utf-8'
33+
final private function __construct(
34+
private string $title,
35+
private string $lang = 'en',
36+
private string $charset = 'utf-8'
3937
) {
40-
$this->title = $title;
41-
$this->lang = $lang;
42-
$this->charset = $charset;
4338
}
4439

45-
// TODO: PHP8 - Element|Comment
46-
/**
47-
* @param Element|Comment $content
48-
*/
49-
public function head(Element|Comment ...$content): Document
40+
public function head(string|Stringable ...$content): Document
5041
{
5142
$this->head = $content;
5243
return $this;
5344
}
5445

55-
// TODO: PHP8 - Element|Comment
56-
/**
57-
* @param Element|Comment|string $content
58-
*/
59-
public function body(Element|Comment|string ...$content): Document
46+
public function body(string|Stringable ...$content): Document
6047
{
6148
$this->body = $content;
6249
return $this;
@@ -96,15 +83,15 @@ private function charset(): string
9683
}
9784

9885
/**
99-
* @return array<Element|Comment> $content
86+
* @return array<string|Stringable>
10087
*/
10188
private function headContent(): array
10289
{
10390
return $this->head;
10491
}
10592

10693
/**
107-
* @return array<Element|Comment|string> $content
94+
* @return array<string|Stringable>
10895
*/
10996
private function bodyContent(): array
11097
{

src/Element.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace Eightfold\HTMLBuilder;
66

7+
use Stringable;
8+
79
use Eightfold\XMLBuilder\Element as XMLElement;
8-
use Eightfold\XMLBuilder\Contracts\Buildable;
910

10-
class Element extends XMLElement implements Buildable
11+
class Element extends XMLElement implements Stringable
1112
{
1213
/**
1314
* The following attributes will be placed in this order if used in an

tests/PerformanceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function document_is_speedy(): void // phpcs:ignore
5858
$elapsed = $end - $start;
5959
$ms = $elapsed/1e+6;
6060

61-
$this->assertLessThan(1, $ms);
61+
$this->assertLessThan(0.8, $ms);
6262
}
6363

6464
/**
@@ -81,6 +81,6 @@ public function document_is_small(): void // phpcs:ignore
8181
$used = $end - $start;
8282
$kb = round($used/1024.2);
8383

84-
$this->assertLessThan(53, $kb);
84+
$this->assertLessThan(65, $kb);
8585
}
8686
}

0 commit comments

Comments
 (0)