Skip to content

Commit 36e2df5

Browse files
committed
add null coalescing
1 parent 94dc571 commit 36e2df5

File tree

22 files changed

+50
-50
lines changed

22 files changed

+50
-50
lines changed

src/Database/Query.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function getSelectTable()
225225
*/
226226
public function findAll( $ids = [], $table = null, $num = null )
227227
{
228-
$num = $num ?? func_num_args();
228+
$num ??= func_num_args();
229229

230230
if(!empty($ids)) {
231231
if(!$table) { $table = $this->query['table']; }
@@ -280,7 +280,7 @@ public function where($column, $arg1 = null, $arg2 = null, $condition = 'AND', $
280280
$whereQuery['condition'] = null;
281281
}
282282

283-
$num = $num ?? func_num_args();
283+
$num ??= func_num_args();
284284
$whereQuery['column'] = $column;
285285

286286
if( $num < 3 ) {
@@ -353,7 +353,7 @@ public function modifyWhere($index, $args, $merge = true, $callback = null)
353353
*/
354354
public function orWhere($column, $arg1, $arg2 = null, $num = null)
355355
{
356-
$num = $num ?? func_num_args();
356+
$num ??= func_num_args();
357357
return $this->where($column, $arg1, $arg2, 'OR', $num);
358358
}
359359

@@ -896,7 +896,7 @@ public function union( Query $query)
896896
public function paginate($number = 25, $page = null, $callback = null)
897897
{
898898
$count_clone = clone $this;
899-
$page = $page ?? $_GET['paged'] ?? $_GET['page'] ?? 1;
899+
$page ??= $_GET['paged'] ?? $_GET['page'] ?? 1;
900900

901901
if(!is_numeric($page)) { $page = 1; }
902902
$page = (int) $page;

src/Elements/BaseForm.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected function autoConfigModel($model = null, $action = null)
185185
$this->itemId = $item_id;
186186
}
187187
elseif($this->resource && !$model) {
188-
$action = $action ?? 'create';
188+
$action ??= 'create';
189189
$model = \TypeRocket\Utility\Helper::modelClass($this->resource);
190190
}
191191

@@ -408,10 +408,10 @@ public function useMenu($menu_id)
408408
public function toUrl($url, $method = null, $site = null)
409409
{
410410
if(str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) {
411-
$site = $site ?? false;
411+
$site ??= false;
412412
}
413413

414-
$site = $site ?? true;
414+
$site ??= true;
415415

416416
switch($method) {
417417
case 'create' :
@@ -484,8 +484,8 @@ public function toPage($resource = null, $action = null, $item_id = null, $root_
484484
$params = ['route_' => [$item_id ?? $this->itemId]];
485485
}
486486

487-
$action = $action ?? $this->action;
488-
$resource = $resource ?? $this->resource;
487+
$action ??= $this->action;
488+
$resource ??= $this->resource;
489489

490490
switch($action) {
491491
case 'create' :
@@ -577,7 +577,7 @@ public static function hiddenInputs($method = 'POST', $prefix = 'tr')
577577
*/
578578
public static function honeypotInputs($name = null)
579579
{
580-
$name = $name ?? 'my_name_' . md5(time());
580+
$name ??= 'my_name_' . md5(time());
581581
$fields = "<input type='text' name='__hny[{$name}]' /><input type='checkbox' name='__hny[send_message]' />";
582582
return Html::div(['style' => 'display: none', 'class' => 'tr-bot-tasty-treat'], $fields);
583583
}

src/Elements/Fields/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function cloneToForm($form = null)
351351
public function setCast($cast, $soft = true)
352352
{
353353
if($soft) {
354-
$this->cast = $this->cast ?? $cast;
354+
$this->cast ??= $cast;
355355
} else {
356356
$this->cast = $cast;
357357
}

src/Elements/Fields/Matrix.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ public static function componentsLoop($builder_data, $other = [], $group = 'buil
449449
* @var $nested
450450
*/
451451
extract($other);
452-
$model = $model ?? null;
453-
$item_id = $item_id ?? null;
454-
$nested = $nested ?? false;
452+
$model ??= null;
453+
$item_id ??= null;
454+
$nested ??= false;
455455
$i = $nested ? 1 : 0;
456-
$info = $info ?? null; // This is an open variable for misc data
456+
$info ??= null; // This is an open variable for misc data
457457
$group = $name ?? $group; // This is to help with migration from v4/v1 to v5
458458
$name = $group;
459459
$len = count($builder_data);

src/Elements/Tabs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected function getActiveTabIndex() {
280280
* @var Tab $tab
281281
*/
282282
foreach ($this->tabs as $i => $tab) {
283-
$first = $first ?? $i;
283+
$first ??= $i;
284284
if($tab->getActive()) {
285285
return $i;
286286
}

src/Elements/Traits/FormConnectorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function extend($group, $escape = true)
257257
*/
258258
public function super($group, $set = null)
259259
{
260-
$set = $set ?? $this;
260+
$set ??= $this;
261261
$dots = method_exists($set, 'getDots') ? $set->getDots() : $set;
262262
return $this->clone()->setGroup($dots . '.' . $group);
263263
}

src/Html/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ protected function el($tag, $attributes = null, $text = null )
145145
protected function form($action, $method = 'GET', $attributes = null, $text = null)
146146
{
147147
if(is_string($attributes) || is_numeric($attributes)) {
148-
$text = $text ?? $attributes;
148+
$text ??= $attributes;
149149
$attributes = [];
150150
}
151151

152-
$attributes = $attributes ?? [];
152+
$attributes ??= [];
153153

154154
$attributes = array_merge( ['action' => $action, 'method' => $method], $attributes );
155155
$this->tag = new Tag( 'form', $attributes, $text );

src/Html/Tag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class Tag implements \Stringable
2121
public function __construct( string $tag, $attributes = null, $nest = null)
2222
{
2323
if(is_string($attributes) || is_numeric($attributes) || $attributes instanceof Tag || $attributes instanceof Html) {
24-
$nest = $nest ?? $attributes;
24+
$nest ??= $attributes;
2525
$attributes = [];
2626
}
2727

28-
$attributes = $attributes ?? [];
28+
$attributes ??= [];
2929

3030
$this->tag = $tag;
3131
$this->attrReset( $attributes );

src/Http/Redirect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function withMessage($message, $type = 'success')
7373
*/
7474
public function withOldFields($fields = null, $notFields = [])
7575
{
76-
$fields = $fields ?? (new Request)->getFields();
76+
$fields ??= (new Request)->getFields();
7777

7878
if($fields instanceof Fields) {
7979
$fields = $fields->getArrayCopy();
@@ -198,7 +198,7 @@ public function toUrl( $url )
198198
public function toRoute($name, $values = [], $site = true, $routes = null)
199199
{
200200
/** @var RouteCollection $routes */
201-
$routes = $routes ?? Container::resolve(RouteCollection::class);
201+
$routes ??= Container::resolve(RouteCollection::class);
202202
$located = $routes->getNamedRoute($name);
203203

204204
if($values instanceof Model) {

src/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function getUriFull()
225225
*/
226226
public function getPathWithoutRoot($root = null)
227227
{
228-
$root = $root ?? get_site_url();
228+
$root ??= get_site_url();
229229
$site = trim( (string) parse_url((string) $root, PHP_URL_PATH), '/');
230230
return ltrim( Str::trimStart(ltrim((string) $this->path, '/'), $site), '/');
231231
}

src/Http/Response.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public function needsBasicAuthentication(string $message = 'Unauthorized', strin
357357
*/
358358
public function setDownloadHeaders($file, $name = null, ?array $headers = null, $type = null)
359359
{
360-
$type = $type ?? 'attachment';
361-
$name = $name ?? pathinfo($file, PATHINFO_BASENAME);
360+
$type ??= 'attachment';
361+
$name ??= pathinfo($file, PATHINFO_BASENAME);
362362
$mime = File::new($file)->mimeType();
363363
$main = array_merge([
364364
'Content-Type' => $mime ?: 'application/octet-stream',
@@ -801,7 +801,7 @@ public function toArray($withReturn = false)
801801
*/
802802
public function withRedirectData($data = null)
803803
{
804-
$data = $data ?? $this->data;
804+
$data ??= $this->data;
805805

806806
if( !empty( $data ) ) {
807807
(new Cookie)->setTransient(Redirect::KEY_DATA, $data);
@@ -823,7 +823,7 @@ public function withRedirectErrors($errors = null, $merge = false)
823823
if($merge) {
824824
$errors = array_merge($this->errors, $errors ?? []);
825825
} else {
826-
$errors = $errors ?? $this->errors;
826+
$errors ??= $this->errors;
827827
}
828828

829829
if( !empty( $errors ) ) {
@@ -843,7 +843,7 @@ public function withRedirectErrors($errors = null, $merge = false)
843843
*/
844844
public function withRedirectMessage($message = null, $type = null)
845845
{
846-
$message = $message ?? $this->message;
846+
$message ??= $this->message;
847847

848848
if(!empty($message)) {
849849
(new Cookie)->setTransient(Redirect::KEY_MESSAGE, [
@@ -865,7 +865,7 @@ public function withRedirectMessage($message = null, $type = null)
865865
*/
866866
public function withOldFields($fields = null, $notFields = []) {
867867

868-
$fields = $fields ?? (new Request)->getFields();
868+
$fields ??= (new Request)->getFields();
869869

870870
if($fields instanceof Fields) {
871871
$fields = $fields->getArrayCopy();
@@ -960,7 +960,7 @@ public function abort($code = null)
960960
*/
961961
public function exitAny( $code = null )
962962
{
963-
$code = $code ?? $this->getStatus();
963+
$code ??= $this->getStatus();
964964
$request = (new Request);
965965

966966
if( $request->isMarkedAjax() || $request->wants('json') ) {
@@ -977,7 +977,7 @@ public function exitAny( $code = null )
977977
*/
978978
public function exitJson( $code = null )
979979
{
980-
$code = $code ?? $this->getStatus();
980+
$code ??= $this->getStatus();
981981
$this->setStatus($code);
982982
wp_send_json( $this );
983983
}
@@ -989,7 +989,7 @@ public function exitJson( $code = null )
989989
*/
990990
public function exitMessage( $code = null )
991991
{
992-
$code = $code ?? $this->getStatus();
992+
$code ??= $this->getStatus();
993993
$this->setStatus($code);
994994
wp_die($this->getMessage(), '', $code);
995995
}

src/Models/Model.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ public function save( $fields = [] )
19871987
*/
19881988
public function saveFields($fields = null)
19891989
{
1990-
$fields = $fields ?? (new Request)->getFields();
1990+
$fields ??= (new Request)->getFields();
19911991

19921992
return $this->save($fields);
19931993
}
@@ -2093,7 +2093,7 @@ public function hasOne($modelClass, $id_foreign = null, $id_local = null, $scope
20932093
}
20942094

20952095
$rel_table = $relationship->getTable();
2096-
$id_foreign = $id_foreign ?? $relationship->getIdColumn();
2096+
$id_foreign ??= $relationship->getIdColumn();
20972097
$id_foreign_where = str_contains($id_foreign, '.') ? $id_foreign : "{$rel_table}.$id_foreign";
20982098

20992099
$id = $this->getPropertyValueDirect($id_local);
@@ -2127,7 +2127,7 @@ public function belongsTo($modelClass, $id_local = null, $id_foreign = null, $sc
21272127
} elseif(is_null($id_foreign) && is_null($scope)) {
21282128
$id_foreign = $relationship->getIdColumn();
21292129
} else {
2130-
$id_foreign = $id_foreign ?? $relationship->getIdColumn();
2130+
$id_foreign ??= $relationship->getIdColumn();
21312131
}
21322132

21332133
if( ! $id_local && $relationship->resource ) {

src/Register/Page.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class Page extends Registrable
5454
public function __construct(string $resource, string $action, string $title, array $settings = [], $handler = null)
5555
{
5656
[$resource, $handle] = array_pad(explode('@', $resource), 2, null);
57-
$handler = $handler ?? $handle;
57+
$handler ??= $handle;
5858

59-
$settings['capability'] = $settings['capability'] ?? $settings['cap'] ?? null;
59+
$settings['capability'] ??= $settings['cap'] ?? null;
6060

6161
$this->setTitle($title);
6262
$this->resource = Sanitize::underscore( $resource );
@@ -760,7 +760,7 @@ protected function loadGlobalVars() {
760760
public static function addResourcePages($singular, $plural = null, array $settings = [], $resource = null, $handler = null)
761761
{
762762
[$singular, $handle] = array_pad(explode('@', $singular), 2, null);
763-
$handler = $handler ?? $handle;
763+
$handler ??= $handle;
764764

765765
if(is_array($plural)) {
766766
$settings = $plural;

src/Register/PostType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PostType extends Registrable
4646
public function __construct( $singular, $plural = null, $settings = null, $id = null )
4747
{
4848
$singularLower = strtolower( trim($singular) );
49-
$id = $id ?? $singularLower;
49+
$id ??= $singularLower;
5050

5151
if(is_array($plural) && is_null($settings)) {
5252
$settings = $plural;

src/Register/Taxonomy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Taxonomy extends Registrable
3535
public function __construct( $singular, $plural = null, $settings = null, $id = null)
3636
{
3737
$lowerSingular = strtolower( trim($singular) );
38-
$id = $id ?? $lowerSingular;
38+
$id ??= $lowerSingular;
3939

4040
if(is_array($plural) && is_null($settings)) {
4141
$settings = $plural;

src/Services/AuthorizerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function auth(AuthUser $user, $option, $action, $policy = null)
9999
}
100100

101101
$policies = $this->getPolicies();
102-
$policy = $policy ?? ($option instanceof Policy ? $option : null);
102+
$policy ??= $option instanceof Policy ? $option : null;
103103

104104
if(!$policy) {
105105
$class = '\\' . get_class($option);

src/Template/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ protected function load($context = null)
237237
*/
238238
public function render($context = null)
239239
{
240-
$context = $context ?? $this->getContext() ?? 'views';
240+
$context ??= $this->getContext() ?? 'views';
241241

242242
$this->load($context);
243243
}

src/Utility/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function makeDir($directory, $premissions = null)
150150
protected function tryToMakeFileWithDir($destination = null)
151151
{
152152
if(!$this->existing) {
153-
$destination = $destination ?? $this->file;
153+
$destination ??= $this->file;
154154
$this->tryToMakeDir($destination);
155155
if($fp = fopen($destination, 'w')) {
156156
fclose($fp);

src/Utility/Jobs/Queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function addJob(JobCanQueue $job, $time = null)
150150
}
151151

152152
$class = get_class($job);
153-
$time = $time ?? (time() + $job::DELAY);
153+
$time ??= time() + $job::DELAY;
154154
$actionName = 'typerocket_job.' . $class;
155155

156156
if(!in_array($class, static::$registered)) {

src/Utility/ModelField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function components($name, $item_id = null, $modelClass = null)
131131

132132
try {
133133
/** @var Model $model */
134-
$modelClass = $modelClass ?? \TypeRocket\Models\WPPost::class;
134+
$modelClass ??= \TypeRocket\Models\WPPost::class;
135135
$model = new $modelClass;
136136
$model->findById($item_id);
137137
} catch (Exception) {

src/Utility/Str.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public static function lower($string, ?string $encoding = null)
397397
*/
398398
public static function encoding(?string $encoding = null) : string
399399
{
400-
$encoding = $encoding ?? mb_internal_encoding();
400+
$encoding ??= mb_internal_encoding();
401401
return ! static::quiet($encoding) ? $encoding : static::UTF8;
402402
}
403403

src/Utility/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ protected function setErrorMessage(ValidatorRule $class, $fullDotPath)
429429
}
430430
}
431431

432-
$this->errors[$fullDotPath] = $this->errors[$fullDotPath] ?? $error_message_full;
433-
$this->errorFields[$fullDotPath] = $this->errorFields[$fullDotPath] ?? trim((string) $error_message);
432+
$this->errors[$fullDotPath] ??= $error_message_full;
433+
$this->errorFields[$fullDotPath] ??= trim((string) $error_message);
434434
}
435435

436436
/**
@@ -506,7 +506,7 @@ protected function validateField($validationRules, $value, string $fullDotPath)
506506
$type = substr((string) $type, 1);
507507
}
508508

509-
$weak = $weak ?? $weak_all;
509+
$weak ??= $weak_all;
510510

511511
if(Str::starts('only_subfields=', $option)) {
512512
$only_subfields = explode('/', (string) $option)[0];

0 commit comments

Comments
 (0)