Skip to content

Commit

Permalink
Fix types for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed Nov 23, 2023
1 parent bc9ef0d commit 2495ff7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Minz/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function setType(string $type): void {
* Return the url for a given file.
*
* @param string $filename name of the file to serve.
* @param 'css'|'js' $type the type (js or css) of the file to serve.
* @param 'css'|'js'|'svg' $type the type (js or css or svg) of the file to serve.
* @param bool $isStatic indicates if the file is a static file or a user file. Default is static.
* @return string url corresponding to the file.
*/
Expand Down
14 changes: 11 additions & 3 deletions lib/Minz/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ class Minz_Mailer {
private int $debug_level;

/**
* Constructor.
* @phpstan-param class-string|'' $viewType
* @param string $viewType Name of the class (inheriting from Minz_View) to use for the view model
*/
public function __construct () {
$this->view = new Minz_View();
public function __construct(string $viewType = '') {
$view = null;
if ($viewType !== '' && class_exists($viewType)) {
$view = new $viewType();
if (!($view instanceof Minz_View)) {
$view = null;
}
}
$this->view = $view ?? new Minz_View();
$this->view->_layout(null);
$this->view->attributeParams();

Expand Down
32 changes: 22 additions & 10 deletions lib/Minz/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function helperToString(string $helper): string {

/**
* Choose the current view layout.
* @param string|null $layout the layout name to use, false to use no layouts.
* @param string|null $layout the layout name to use, null to use no layouts.
*/
public function _layout(?string $layout): void {
if ($layout != null) {
Expand Down Expand Up @@ -205,7 +205,7 @@ public static function appendTitle(string $title): void {
*/
public static function headStyle(): string {
$styles = '';
foreach(self::$styles as $style) {
foreach (self::$styles as $style) {
$styles .= '<link rel="stylesheet" ' .
($style['media'] === 'all' ? '' : 'media="' . $style['media'] . '" ') .
'href="' . $style['url'] . '" />';
Expand All @@ -220,10 +220,13 @@ public static function headStyle(): string {
* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated
*/
public static function prependStyle(string $url, string $media = 'all', bool $cond = false): void {
array_unshift (self::$styles, array (
if ($url === '') {
return;
}
array_unshift(self::$styles, [
'url' => $url,
'media' => $media,
));
]);
}

/**
Expand All @@ -233,10 +236,13 @@ public static function prependStyle(string $url, string $media = 'all', bool $co
* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated
*/
public static function appendStyle(string $url, string $media = 'all', bool $cond = false): void {
self::$styles[] = array (
if ($url === '') {
return;
}
self::$styles[] = [
'url' => $url,
'media' => $media,
);
];
}

/**
Expand Down Expand Up @@ -298,12 +304,15 @@ public static function headScript(): string {
* @param string $id Add a script `id` attribute
*/
public static function prependScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void {
array_unshift(self::$scripts, array (
if ($url === '') {
return;
}
array_unshift(self::$scripts, [
'url' => $url,
'defer' => $defer,
'async' => $async,
'id' => $id,
));
]);
}

/**
Expand All @@ -315,12 +324,15 @@ public static function prependScript(string $url, bool $cond = false, bool $defe
* @param string $id Add a script `id` attribute
*/
public static function appendScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void {
self::$scripts[] = array (
if ($url === '') {
return;
}
self::$scripts[] = [
'url' => $url,
'defer' => $defer,
'async' => $async,
'id' => $id,
);
];
}

/**
Expand Down

0 comments on commit 2495ff7

Please sign in to comment.