Skip to content

Commit d6925fc

Browse files
author
Wazabii
committed
Types
1 parent 1c1d7b1 commit d6925fc

File tree

4 files changed

+40
-55
lines changed

4 files changed

+40
-55
lines changed

Dom/Document.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Document
3030
private $elem;
3131
private static $inst;
3232

33-
public function __toString()
33+
public function __toString(): string
3434
{
3535
return $this->get();
3636
}
@@ -50,7 +50,7 @@ public function get()
5050
/**
5151
* Init DOM instance
5252
* @param string $key DOM access key
53-
* @return new self
53+
* @return self
5454
*/
5555
public static function dom(string $key)
5656
{
@@ -121,9 +121,9 @@ public function createPrepend(string $element, ?string $value = null, ?string $b
121121

122122
/**
123123
* Get one element from key
124-
* @return Response\Dom\Element
124+
* @return Element
125125
*/
126-
public function getElement(string $key)
126+
public function getElement(string $key): Element
127127
{
128128
return ($this->elements[$key] ?? null);
129129
}

Interfaces/JsonInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public function get(?string $key = null);
4141

4242
/**
4343
* Convert json array to json string
44-
* @param Bitmask $options Bitmask
45-
* @param integer $depth Set the maximum depth. Must be greater than zero
44+
* @param int $options Bitmask
45+
* @param int $depth Set the maximum depth. Must be greater than zero
4646
* @return json/bool (bool if could not load json data)
4747
*/
48-
public function encode($options = JSON_UNESCAPED_UNICODE, $depth = 512): string;
48+
public function encode(int $options = JSON_UNESCAPED_UNICODE, int $depth = 512): string;
4949

5050
/**
5151
* Decode json data

Json.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct()
3030
}
3131

3232

33-
public function __toString()
33+
public function __toString(): string
3434
{
3535
return $this->encode();
3636
}
@@ -169,7 +169,7 @@ public function data(?string $key = null)
169169

170170
/**
171171
* Get data has HTML friendly string
172-
* @param string $str select key (you can use comma sep. to traverse array)
172+
* @param string $key select key (you can use comma sep. to traverse array)
173173
* @return string
174174
*/
175175
public function output(string $key): ?string
@@ -183,11 +183,11 @@ public function output(string $key): ?string
183183

184184
/**
185185
* Convert json array to json string
186-
* @param Bitmask $options Bitmask
187-
* @param integer $depth Set the maximum depth. Must be greater than zero
188-
* @return json/bool (bool if could not load json data)
186+
* @param int $options Bitmask
187+
* @param int $depth Set the maximum depth. Must be greater than zero
188+
* @return json/bool (bool if could not load json data)
189189
*/
190-
public function encode($options = JSON_UNESCAPED_UNICODE, $depth = 512): string
190+
public function encode(int $options = JSON_UNESCAPED_UNICODE, int $depth = 512): string
191191
{
192192
return self::encodeData($this->data, $options, $depth);
193193
}
@@ -240,12 +240,12 @@ private function select(string $key)
240240

241241
/**
242242
* Json encode data
243-
* @param array $json array to json
244-
* @param opt $flag read php.net (or use the default)
245-
* @param int $depth read php.net
243+
* @param array $json array to json
244+
* @param int $flag read php.net (or use the default)
245+
* @param int $depth read php.net
246246
* @return string|null
247247
*/
248-
final protected static function encodeData(array $json, $flag = JSON_UNESCAPED_UNICODE, int $depth = 512): ?string
248+
final protected static function encodeData(array $json, int $flag = JSON_UNESCAPED_UNICODE, int $depth = 512): ?string
249249
{
250250
if (is_array($json) && count($json) > 0 && ($encode = json_encode($json, $flag, $depth))) {
251251
return $encode;

SwiftRender.php

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function setFile(string $file): self
103103

104104
/**
105105
* Set dir path to index files
106-
* @param string $type Template type (index/partial/view)
107106
* @param string $dir Dir path
108107
* @return self
109108
*/
@@ -116,7 +115,6 @@ public function setIndexDir(string $dir): self
116115

117116
/**
118117
* Set dir path to view files
119-
* @param string $type Template type (index/partial/view)
120118
* @param string $dir Dir path
121119
* @return self
122120
*/
@@ -141,7 +139,6 @@ public function setBufferDir(string $dir): self
141139

142140
/**
143141
* Set dir path to partial files
144-
* @param string $type Template type (index/partial/view)
145142
* @param string $dir Dir path
146143
* @return self
147144
*/
@@ -216,11 +213,10 @@ public function withView(string $file, array $args = array()): self
216213
*/
217214
public function setPartial(string $keyA, string|array $keyB = array(), array $keyC = array()): self
218215
{
216+
$partial = $keyB;
219217
if (is_array($keyB)) {
220218
$keyC = $keyB;
221219
$partial = $keyA;
222-
} else {
223-
$partial = $keyB;
224220
}
225221

226222
if (is_null($this->file)) {
@@ -293,7 +289,6 @@ public function index(?array $args = null): self
293289

294290
/**
295291
* Prepare buffer for return
296-
* @param boolean $args Overwrite arguments
297292
* @return self
298293
*/
299294
public function buffer(): self
@@ -305,7 +300,7 @@ public function buffer(): self
305300
/**
306301
* Prepare view for return
307302
* @param array|null $args Overwrite arguments
308-
* @return slef
303+
* @return self
309304
*/
310305
public function view(?array $args = null): self
311306
{
@@ -370,13 +365,13 @@ final public function get(?array $args = null): string
370365
private function buildView(): void
371366
{
372367
if (!is_null($this->bindView)) {
373-
if (($hasBuffer = $this->existAtGet("buffer")) || ($hasIndex = $this->existAtGet("index"))) {
374-
if ($hasBuffer) {
375-
$this->buffer = $this->bindView;
376-
}
377-
if ($hasIndex) {
378-
$this->view = $this->bindView;
379-
}
368+
$hasBuffer = $this->existAtGet("buffer");
369+
$hasIndex = $this->existAtGet("index");
370+
if ($hasBuffer) {
371+
$this->buffer = $this->bindView;
372+
}
373+
if ($hasIndex) {
374+
$this->view = $this->bindView;
380375
}
381376
}
382377
}
@@ -407,8 +402,7 @@ private function build(string|callable $file, array $args = array()): callable
407402
if (is_array($argsFromFile) && count($argsFromFile) > 0) {
408403
$args = $argsFromFile;
409404
}
410-
$obj = Traverse::value($args);
411-
include($filePath);
405+
$this->inclRouterFileData($filePath, Traverse::value($args), $args);
412406
} else {
413407
throw new Exception("Could not require template file add {$this->get}: {$dir}{$file}.", 1);
414408
}
@@ -453,6 +447,19 @@ private function existAtGet(string $key): bool
453447
return (bool)(isset($this->{$key}) && $this->get === $key);
454448
}
455449

450+
/**
451+
* Include router file with router object data
452+
* @param string $filePath
453+
* @param object $obj
454+
* @param array $args
455+
* @psalm-suppress UnusedParam
456+
* @return void
457+
*/
458+
private function inclRouterFileData(string $filePath, object $obj, array $args): void
459+
{
460+
include($filePath);
461+
}
462+
456463
public function dom(string $key): Document
457464
{
458465
return Document::dom($key);
@@ -473,26 +480,4 @@ public function isEl($elem): bool
473480
{
474481
return (bool)($elem instanceof Element);
475482
}
476-
477-
/*
478-
function dom(string $key): Document
479-
{
480-
return Document::dom($key);
481-
}
482-
function createTag(string $element, string $value, ?array $attr = NULL) {
483-
$inst = new Document();
484-
$el = $inst->create($element, $value)->attrArr($attr);
485-
return $el;
486-
}
487-
488-
function isDoc($el): bool
489-
{
490-
return (bool)($el instanceof Document || $el instanceof Element);
491-
}
492-
493-
function isEl($el): bool
494-
{
495-
return (bool)($el instanceof Element);
496-
}
497-
*/
498483
}

0 commit comments

Comments
 (0)