Skip to content

Commit

Permalink
System: use elvis operator
Browse files Browse the repository at this point in the history
  • Loading branch information
esyede committed Aug 17, 2024
1 parent ae4d3b8 commit 52dc4c7
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion system/carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct($time = null, $tz = null)
$time = $test->toDateTimeString();
}

parent::__construct($time ? $time : 'now', static::safeCreateDateTimeZone($tz));
parent::__construct($time ?: 'now', static::safeCreateDateTimeZone($tz));
}

protected static function safeCreateDateTimeZone($tz)
Expand Down
2 changes: 1 addition & 1 deletion system/curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public static function body_file($path, $alias = '')
return curl_file_create($path, $mime, $alias);
}

return sprintf('@%s;filename=%s;type=%s', $path, $alias ? $alias : basename($path), $mime);
return sprintf('@%s;filename=%s;type=%s', $path, $alias ?: basename($path), $mime);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/database/facile/relationships/belongstomany.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BelongsToMany extends Relationship
public function __construct($model, $associated, $table, $foreign, $other)
{
$this->other = $other;
$this->joining = $table ? $table : $this->joining($model, $associated);
$this->joining = $table ?: $this->joining($model, $associated);

if (Pivot::$timestamps) {
$this->with[] = 'created_at';
Expand Down
2 changes: 1 addition & 1 deletion system/foundation/faker/provider/id/person.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function suffix()
public function nik($gender = null, $birthDate = null)
{
$nik = $this->birthPlaceCode() . $this->generator->numerify('##');
$birthDate = $birthDate ? $birthDate : $this->generator->dateTimeBetween();
$birthDate = $birthDate ?: $this->generator->dateTimeBetween();

if (!$gender) {
$gender = $this->generator->randomElement([self::GENDER_MALE, self::GENDER_FEMALE]);
Expand Down
4 changes: 2 additions & 2 deletions system/foundation/http/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ public function overrideGlobals()
$request = ['g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE];

$orderings = ini_get('request_order');
$orderings = (string) ($orderings ? $orderings : ini_get('variable_order'));
$orderings = (string) ($orderings ?: ini_get('variable_order'));
$orderings = preg_replace('/[^cgp]/', '', strtolower($orderings));
$orderings = $orderings ? $orderings : 'gp';
$orderings = $orderings ?: 'gp';

$_REQUEST = [];
$orders = str_split($orderings);
Expand Down
4 changes: 2 additions & 2 deletions system/foundation/http/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function prepare(Request $request)
}
}

$charset = $this->charset ? $this->charset : 'UTF-8';
$charset = $this->charset ?: 'UTF-8';

if (!$headers->has('Content-Type')) {
$headers->set('Content-Type', 'text/html; charset=' . $charset);
Expand Down Expand Up @@ -520,7 +520,7 @@ public function setDate(\DateTime $date)
public function getAge()
{
$age = $this->headers->get('Age');
return $age ? $age : max(time() - $this->getDate()->format('U'), 0);
return $age ?: max(time() - $this->getDate()->format('U'), 0);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/foundation/http/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,9 @@ public function __construct(
}

$this->originalName = $this->getName($origName);
$this->mimeType = $mimeType ? $mimeType : 'application/octet-stream';
$this->mimeType = $mimeType ?: 'application/octet-stream';
$this->size = $size;
$this->error = $error ? $error : UPLOAD_ERR_OK;
$this->error = $error ?: UPLOAD_ERR_OK;
$this->test = (bool) $test;

if (UPLOAD_ERR_OK === $this->error && !is_file($path)) {
Expand Down
2 changes: 1 addition & 1 deletion system/foundation/oops/bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function renderLoader()
throw new \LogicException('Session started before debugger enabled.');
}

$this->contentId = $this->contentId ? $this->contentId : substr(md5(uniqid('', true)), 0, 10);
$this->contentId = $this->contentId ?: substr(md5(uniqid('', true)), 0, 10);
$contentId = $this->contentId;
$nonce = Helpers::getNonce();
$async = true;
Expand Down
4 changes: 1 addition & 3 deletions system/foundation/oops/debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,7 @@ public static function barDump($var, $title = null, array $options = null)
$panel->data[] = ['title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
Dumper::LOCATION => self::$showLocation
? self::$showLocation
: (Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE),
Dumper::LOCATION => self::$showLocation ?: (Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE),
])];
}

Expand Down
2 changes: 1 addition & 1 deletion system/foundation/oops/dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private static function toJson(&$var, $options, $level = 0)

static $counter = 1;

$obj = $obj ? $obj : [
$obj = $obj ?: [
'id' => self::$livePrefix . '0' . $counter++,
'name' => Helpers::getClass($var),
'editor' => $editorInfo,
Expand Down
4 changes: 2 additions & 2 deletions system/foundation/oops/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ public static function improveException($e)
} elseif (preg_match('#^Call to undefined function (\S+\\\\)?(\w+)\(#', $message, $m)) {
$funcs = array_merge(get_defined_functions()['internal'], get_defined_functions()['user']);
$hint = self::getSuggestion($funcs, $m[1] . $m[2]);
$hint = $hint ? $hint : self::getSuggestion($funcs, $m[2]);
$hint = $hint ?: self::getSuggestion($funcs, $m[2]);
$message = "Call to undefined function $m[2](), did you mean $hint()?";
$replace = ["$m[2](", "$hint("];
} elseif (preg_match('#^Call to undefined method ([\w\\\\]+)::(\w+)#', $message, $m)) {
$hint = get_class_methods($m[1]);
$hint = self::getSuggestion($hint ? $hint : [], $m[2]);
$hint = self::getSuggestion($hint ?: [], $m[2]);
$message .= ", did you mean $hint()?";
$replace = ["$m[2](", "$hint("];
} elseif (preg_match('#^Undefined variable: (\w+)#', $message, $m) && !empty($e->context)) {
Expand Down
6 changes: 3 additions & 3 deletions system/foundation/oops/logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public function getExceptionFile($exception)
*/
protected function logException($exception, $file = null)
{
$file = $file ? $file : $this->getExceptionFile($exception);
$panic = $this->panic ? $this->panic : new Panic();
$file = $file ?: $this->getExceptionFile($exception);
$panic = $this->panic ?: new Panic();

// FIXME: Apakah log html detail error juga perlu dirender?
// $panic->renderToFile($exception, $file);
Expand Down Expand Up @@ -247,7 +247,7 @@ public function defaultMailer($message, $email)
["\n", PHP_EOL],
[
'headers' => implode("\n", [
'From: ' . ($this->fromEmail ? $this->fromEmail : "noreply@$host"),
'From: ' . ($this->fromEmail ?: "noreply@$host"),
'X-Mailer: Rakit debugger',
'Content-Type: text/plain; charset=UTF-8',
'Content-Transfer-Encoding: 8bit',
Expand Down
2 changes: 1 addition & 1 deletion system/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function session($key, $default = null)
*/
function fake($locale = null)
{
return \System\Foundation\Faker\Factory::create($locale ? $locale : config('application.language'));
return \System\Foundation\Faker\Factory::create($locale ?: config('application.language'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/jwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function decode($token, $secret)
}

$jwt = explode('.', $token);
$timestamp = static::$timestamp ? static::$timestamp : time();
$timestamp = static::$timestamp ?: time();

if (!is_array($jwt) || count($jwt) !== 3) {
throw new \Exception('Wrong number of segments');
Expand Down
2 changes: 1 addition & 1 deletion system/lottery.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static function fix($sequence, $when_missing = null)
public static function sequence($sequence, $when_missing = null)
{
$next = 0;
$when_missing = $when_missing ? $when_missing : function ($chances, $out_of) use (&$next) {
$when_missing = $when_missing ?: function ($chances, $out_of) use (&$next) {
$cache = static::$factory;
static::$factory = null;
$factory = static::factory();
Expand Down
2 changes: 1 addition & 1 deletion system/routing/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected static function root($identifier, $controller, $root)
$home = ('home' === $controller) ? '' : dirname((string) $controller);
$pattern = trim($root . '/' . $home, '/');

static::register('*', $pattern ? $pattern : '/', ['uses' => $identifier . '@index']);
static::register('*', $pattern ?: '/', ['uses' => $identifier . '@index']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/str.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public static function replace_array($search, array $replace, $subject)

foreach ($segments as $segment) {
$replacer = array_shift($replace);
$result .= ($replacer ? $replacer : $search) . $segment;
$result .= ($replacer ?: $search) . $segment;
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion system/uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function current()
protected static function format($uri)
{
$url = trim($uri, '/');
return $url ? $url : '/';
return $url ?: '/';
}

/**
Expand Down

0 comments on commit 52dc4c7

Please sign in to comment.