Skip to content

Commit

Permalink
Merge pull request #1129 from HDInnovations/development
Browse files Browse the repository at this point in the history
(Refactor) Count On Null
  • Loading branch information
HDVinnie authored Feb 13, 2020
2 parents fffa67c + 285ecfa commit 8ae69c6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/GitUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function update()
{
$updating = $this->checkForUpdates();

if (count($updating) > 0) {
if ((is_countable($updating) ? count($updating) : 0) > 0) {
$this->alertDanger('Found Updates');

$this->cyan('Files that need updated:');
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/LanguageCensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function censor($source)
$indexes = self::matchWordIndexes($source, $word);
$ignore = 0;
for ($i = 0; $i < $length; $i++) {
if (count($indexes) > 0 && $indexes[0] == $i) {
if ((is_countable($indexes) ? count($indexes) : 0) > 0 && $indexes[0] == $i) {
$match = substr($source, $indexes[0], $word_length);
$result .= "<span class='censor'>{$match}</span>";
$ignore = $word_length - 1;
Expand Down
14 changes: 7 additions & 7 deletions app/Helpers/TorrentTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static function normalizeTorrent($torrentFile)
public static function getFileCount($decodedTorrent)
{
// Multiple file torrent ?
if (array_key_exists('files', $decodedTorrent['info']) && count($decodedTorrent['info']['files'])) {
return count($decodedTorrent['info']['files']);
if (array_key_exists('files', $decodedTorrent['info']) && (is_countable($decodedTorrent['info']['files']) ? count($decodedTorrent['info']['files']) : 0)) {
return is_countable($decodedTorrent['info']['files']) ? count($decodedTorrent['info']['files']) : 0;
}

return 1;
Expand All @@ -89,11 +89,11 @@ public static function getFileCount($decodedTorrent)
public static function getTorrentSize($decodedTorrent)
{
$size = 0;
if (array_key_exists('files', $decodedTorrent['info']) && count($decodedTorrent['info']['files'])) {
if (array_key_exists('files', $decodedTorrent['info']) && (is_countable($decodedTorrent['info']['files']) ? count($decodedTorrent['info']['files']) : 0)) {
foreach ($decodedTorrent['info']['files'] as $k => $file) {
$dir = '';
$size += $file['length'];
$count = count($file['path']);
$count = is_countable($file['path']) ? count($file['path']) : 0;
}
} else {
$size = $decodedTorrent['info']['length'];
Expand All @@ -112,10 +112,10 @@ public static function getTorrentSize($decodedTorrent)
*/
public static function getTorrentFiles($decodedTorrent)
{
if (array_key_exists('files', $decodedTorrent['info']) && count($decodedTorrent['info']['files'])) {
if (array_key_exists('files', $decodedTorrent['info']) && (is_countable($decodedTorrent['info']['files']) ? count($decodedTorrent['info']['files']) : 0)) {
foreach ($decodedTorrent['info']['files'] as $k => $file) {
$dir = '';
$count = count($file['path']);
$count = is_countable($file['path']) ? count($file['path']) : 0;
for ($i = 0; $i < $count; $i++) {
if (($i + 1) == $count) {
$fname = $dir.$file['path'][$i];
Expand Down Expand Up @@ -157,7 +157,7 @@ public static function getTorrentHash($decodedTorrent)
public static function getTorrentFileCount($decodedTorrent)
{
if (array_key_exists('files', $decodedTorrent['info'])) {
return count($decodedTorrent['info']['files']);
return is_countable($decodedTorrent['info']['files']) ? count($decodedTorrent['info']['files']) : 0;
}

return 1;
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/API/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function echoes()
{
$user = User::with(['echoes'])->findOrFail($this->auth->user()->id);

if (!$user->echoes || count($user->echoes->toArray()) < 1) {
if (!$user->echoes || (is_countable($user->echoes->toArray()) ? count($user->echoes->toArray()) : 0) < 1) {
$echoes = new UserEcho();
$echoes->user_id = $this->auth->user()->id;
$echoes->room_id = 1;
Expand All @@ -76,7 +76,7 @@ public function audibles()
{
$user = User::with(['audibles'])->findOrFail($this->auth->user()->id);

if (!$user->audibles || count($user->audibles->toArray()) < 1) {
if (!$user->audibles || (is_countable($user->audibles->toArray()) ? count($user->audibles->toArray()) : 0) < 1) {
$audibles = new UserAudible();
$audibles->user_id = $this->auth->user()->id;
$audibles->room_id = 1;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function quickthanks(Request $request, $id)
];
}

$selected = mt_rand(0, count($thankArray) - 1);
$selected = mt_rand(0, (is_countable($thankArray) ? count($thankArray) : 0) - 1);
$comment->content = $thankArray[$selected];
$comment->user_id = $user->id;
$comment->torrent_id = $torrent->id;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Staff/BackupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index(Request $request)
$user = $request->user();
abort_unless($user->group->is_owner, 403);

if (!count(config('backup.backup.destination.disks'))) {
if (!(is_countable(config('backup.backup.destination.disks')) ? count(config('backup.backup.destination.disks')) : 0)) {
dd(trans('backup.no_disks_configured'));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/ChatRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function checkMessageLimits($room_id)
{
$messages = $this->messages($room_id)->toArray();
$limit = config('chat.message_limit');
$count = count($messages);
$count = is_countable($messages) ? count($messages) : 0;

// Lets purge all old messages and keep the database to the limit settings
if ($count > $limit) {
Expand Down

0 comments on commit 8ae69c6

Please sign in to comment.