new isset syntax. the future is here

This commit is contained in:
Alex Grintsvayg 2016-09-05 15:51:52 -04:00
parent dee1ec373e
commit a05ac0bfa9
12 changed files with 26 additions and 27 deletions

View file

@ -11,7 +11,7 @@ class Autoloader
}
$class = strtolower($class);
$path = isset(static::$classes[$class]) ? static::$classes[$class] : false;
$path = static::$classes[$class] ?? false;
if ($path)
{

View file

@ -9,7 +9,7 @@ class Actions
{
public static function param($key, $default = null)
{
return isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default);
return $_POST[$key] ?? $_GET[$key] ?? $default;
}
//this is dumb

View file

@ -8,7 +8,7 @@ class Controller
{
$viewAndParams = static::execute($uri);
$viewTemplate = $viewAndParams[0];
$viewParameters = isset($viewAndParams[1]) ? $viewAndParams[1] : [];
$viewParameters = $viewAndParams[1] ?? [];
if (!IS_PRODUCTION && isset($viewAndParams[2]))
{
throw new Exception('use response::setheader instead of returning headers');
@ -27,7 +27,7 @@ class Controller
$layout = !(isset($viewParameters['_no_layout']) && $viewParameters['_no_layout']);
unset($viewParameters['_no_layout']);
$layoutParams = isset($viewParameters[View::LAYOUT_PARAMS]) ? $viewParameters[View::LAYOUT_PARAMS] : [];
$layoutParams = $viewParameters[View::LAYOUT_PARAMS] ?? [];
unset($viewParameters[View::LAYOUT_PARAMS]);
$content = View::render($viewTemplate, $viewParameters + ['fullPage' => true]);

View file

@ -36,15 +36,14 @@ class Request
public static function getOriginalIp(): string
{
return isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] :
(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
trim(explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])[0]) :
(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''));
return $_SERVER['HTTP_X_REAL_IP'] ??
(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? trim(explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])[0]) :
($_SERVER['REMOTE_ADDR'] ?? ''));
}
public static function getUserAgent(): string
{
return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
return $_SERVER['HTTP_USER_AGENT'] ?? '';
}
public static function getHost(): string
@ -55,7 +54,7 @@ class Request
public static function getRelativeUri(): string
{
return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
return $_SERVER['REQUEST_URI'] ?? '';
}
public static function isGzipAccepted(): bool

View file

@ -32,7 +32,7 @@ class Session
public static function get($key, $default = null)
{
return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
return $_SESSION[$key] ?? $default;
}
public static function set($key, $value)

View file

@ -193,7 +193,7 @@ class ContentActions extends Actions
public static function preparePostListPartial(array $vars): array
{
$count = isset($vars['count']) ? $vars['count'] : 3;
$count = $vars['count'] ?? 3;
return [
'posts' => array_slice(Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC), 0, $count)
];

View file

@ -16,7 +16,7 @@ class MailActions extends Actions
return Controller::redirect($nextUrl);
}
Session::set(Session::KEY_LIST_SUB_SIGNATURE, isset($_POST['listSig']) ? $_POST['listSig'] : true);
Session::set(Session::KEY_LIST_SUB_SIGNATURE, $_POST['listSig'] ?? true);
$email = $_POST['email'];
if (!$email|| !filter_var($email, FILTER_VALIDATE_EMAIL))
@ -37,7 +37,7 @@ class MailActions extends Actions
{
Session::set(Session::KEY_MAILCHIMP_LIST_IDS, array_merge(Session::get(Session::KEY_MAILCHIMP_LIST_IDS, []), [$mcListId]));
Session::set(Session::KEY_LIST_SUB_SUCCESS, true);
Session::set(Session::KEY_LIST_SUB_FB_EVENT, isset($_POST['fbEvent']) ? $_POST['fbEvent'] : null);
Session::set(Session::KEY_LIST_SUB_FB_EVENT, $_POST['fbEvent'] ?? null);
}
else
{

View file

@ -28,8 +28,8 @@ class Debug
$rtn .= sprintf("#%s %s(%s): %s(%s)\n",
$count,
isset($frame['file']) ? $frame['file'] : 'unknown file',
isset($frame['line']) ? $frame['line'] : 'unknown line',
$frame['file'] ?? 'unknown file',
$frame['line'] ?? 'unknown line',
isset($frame['class']) ? $frame['class'].$frame['type'].$frame['function'] : $frame['function'],
$args);
}

View file

@ -48,12 +48,12 @@ class Post
$this->slug = $slug;
$this->markdown = $markdown;
$this->metadata = $frontMatter;
$this->title = isset($frontMatter['title']) ? $frontMatter['title'] : null;
$this->author = isset($frontMatter['author']) ? $frontMatter['author'] : null;
$this->title = $frontMatter['title'] ?? null;
$this->author = $frontMatter['author'] ?? null;
$this->date = isset($frontMatter['date']) ? new DateTime($frontMatter['date']) : null;
$this->cover = isset($frontMatter['cover']) ? $frontMatter['cover'] : null;
$this->cover = $frontMatter['cover'] ?? null;
$this->isCoverLight = isset($frontMatter['cover-light']) && $frontMatter['cover-light'] == 'true';
$this->category = isset($frontMatter['category']) ? $frontMatter['category'] : null;
$this->category = $frontMatter['category'] ?? null;
}
public static function find($folder, $sort = null)
@ -349,7 +349,7 @@ class Post
{
$values = array_unique(array_map(function(Post $post) use($field) {
$metadata = $post->getMetadata();
return isset($metadata[$field]) ? $metadata[$field] : null;
return $metadata[$field] ?? null;
}, $posts));
sort($values);
return array_combine($values, $values);

View file

@ -204,7 +204,7 @@ class Response
foreach (preg_split('/\s*,\s*/', $cacheControl) as $tmp)
{
$tmp = explode('=', $tmp);
$currentHeaders[$tmp[0]] = isset($tmp[1]) ? $tmp[1] : null;
$currentHeaders[$tmp[0]] = $tmp[1] ?? null;
}
}
$currentHeaders[strtr(strtolower($name), '_', '-')] = $value;
@ -236,7 +236,7 @@ class Response
public static function getHeader($name, $default = null)
{
return isset(static::$headers[$name]) ? static::$headers[$name] : $default;
return static::$headers[$name] ?? $default;
}
public static function getHeaders(): array
@ -350,7 +350,7 @@ class Response
'505' => 'HTTP Version Not Supported',
];
return isset($statusTexts[$code]) ? $statusTexts[$code] : null;
return $statusTexts[$code] ?? null;
}
protected static function normalizeHeaderName($name)

View file

@ -1,4 +1,4 @@
<?php $title = isset($title) ? $title : __('download.other') ?>
<?php $title = $title ?? __('download.other') ?>
<div class="cover cover-light content content-light">
<h3><?php echo $title ?></h3>
<?php $buckets = array_fill(0, 3, []) ?>

View file

@ -1,4 +1,4 @@
<?php $error = isset($error) ? $error : null ?>
<?php $error = $error ?? null ?>
<form action="/list-subscribe" method="post" novalidate>
<?php if ($error): ?>
@ -18,7 +18,7 @@
<input type="hidden" name="listId" value="<?php echo $listId ?>"/>
<input type="hidden" name="listSig" value="<?php echo $listSig ?>"/>
<input type="email" value="" name="email" class="required email standard" placeholder= "<?php echo __('email.placeholder') ?>">
<input type="submit" value="<?php echo isset($submitLabel) ? $submitLabel : __('email.subs') ?>" name="subscribe" class="<?php echo $btnClass ?>">
<input type="submit" value="<?php echo $submitLabel ?? __('email.subs') ?>" name="subscribe" class="<?php echo $btnClass ?>">
<?php if (isset($fbEvent)): ?>
<input type="hidden" name="fbEvent" value="<?php echo $fbEvent ?>" />
<?php endif ?>