Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use string and array classes instead of helpers #2605

Merged
merged 3 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ New features:

Enhancements:

*
* Use string and array classes instead of helpers

Fixes:

Expand Down
3 changes: 2 additions & 1 deletion app/Helpers/CollectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class CollectionHelper
Expand Down Expand Up @@ -57,7 +58,7 @@ public static function getCollator($locale = null)
if (! $locale) {
$locale = app()->getLocale();
}
if (! array_has($collators, $locale)) {
if (! Arr::has($collators, $locale)) {
$collator = new \Collator($locale);

if (LocaleHelper::getLang($locale) == 'fr') {
Expand Down
5 changes: 3 additions & 2 deletions app/Helpers/CountriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;
use PragmaRX\CountriesLaravel\Package\Facade as Countries;
use PragmaRX\Countries\Package\Support\Collection as Country;
Expand Down Expand Up @@ -71,8 +72,8 @@ private static function getCommonNameLocale($country)
$locale = App::getLocale();
$lang = LocaleHelper::getLocaleAlpha($locale);

return array_get($country, 'translations.'.$lang.'.common',
array_get($country, 'name.common', '')
return Arr::get($country, 'translations.'.$lang.'.common',
Arr::get($country, 'name.common', '')
);
}

Expand Down
5 changes: 3 additions & 2 deletions app/Helpers/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use Illuminate\Support\Arr;
use Matriphe\ISO639\ISO639;
use Illuminate\Support\Facades\App;
use libphonenumber\PhoneNumberUtil;
Expand Down Expand Up @@ -145,8 +146,8 @@ public static function getDirection()
*/
public static function getLocaleAlpha($locale)
{
if (array_has(static::$locales, $locale)) {
return array_get(static::$locales, $locale);
if (Arr::has(static::$locales, $locale)) {
return Arr::get(static::$locales, $locale);
}
$locale = mb_strtolower($locale);
$languages = (new ISO639)->allLanguages();
Expand Down
9 changes: 5 additions & 4 deletions app/Helpers/RequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Helpers;

use Vectorface\Whip\Whip;
use Illuminate\Support\Arr;
use OK\Ipstack\Client as Ipstack;
use Illuminate\Support\Facades\Request;
use Stevebauman\Location\Facades\Location;
Expand Down Expand Up @@ -56,11 +57,11 @@ public static function infos($ip)
$ipstack = new Ipstack(config('location.ipstack_apikey'));
$position = $ipstack->get($ip ?? static::ip(), true);

if (! is_null($position) && array_get($position, 'country_code', null)) {
if (! is_null($position) && Arr::get($position, 'country_code', null)) {
return [
'country' => array_get($position, 'country_code', null),
'currency' => array_get($position, 'currency.code', null),
'timezone' => array_get($position, 'time_zone.id', null),
'country' => Arr::get($position, 'country_code', null),
'currency' => Arr::get($position, 'currency.code', null),
'timezone' => Arr::get($position, 'time_zone.id', null),
];
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Helpers/TimezoneHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Helpers;

use DateTimeZone;
use Illuminate\Support\Arr;

class TimezoneHelper
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public static function getListOfTimezones() : array

$result = [];
foreach ($collect as $item) {
$values = array_values(array_sort($item, function ($value) {
$values = array_values(Arr::sort($item, function ($value) {
return $value['name'];
}));
foreach ($values as $val) {
Expand Down
3 changes: 2 additions & 1 deletion app/Helpers/VCardHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use Illuminate\Support\Arr;
use Sabre\VObject\Component\VCard;

class VCardHelper
Expand All @@ -20,7 +21,7 @@ public static function getCountryISOFromSabreVCard(VCard $vCard)
return;
}

$country = array_get($vCardAddress->getParts(), '6');
$country = Arr::get($vCardAddress->getParts(), '6');
if (! empty($country)) {
return CountriesHelper::find($country);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Helpers\DateHelper;
use App\Jobs\ResizeAvatars;
use App\Models\Contact\Tag;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\LocaleHelper;
Expand Down Expand Up @@ -538,7 +539,7 @@ public function vCard(Contact $contact)

return response($vcard->serialize())
->header('Content-type', 'text/x-vcard')
->header('Content-Disposition', 'attachment; filename='.str_slug($contact->name, '-', LocaleHelper::getLang()).'.vcf');
->header('Content-Disposition', 'attachment; filename='.Str::slug($contact->name, '-', LocaleHelper::getLang()).'.vcf');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/DAV/Backend/CalDAV/CalDAVTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\DAV\Backend\CalDAV;

use Sabre\DAV;
use Illuminate\Support\Arr;
use App\Models\Contact\Task;
use App\Services\Task\DestroyTask;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -140,7 +141,7 @@ public function updateOrCreateCalendarObject($objectUri, $calendarData)
'entry' => $calendarData,
]);

if (! array_has($result, 'error')) {
if (! Arr::has($result, 'error')) {
$task = Task::where('account_id', Auth::user()->account_id)
->find($result['task_id']);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/DAV/Backend/CardDAV/CardDAVBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\DAV\Backend\CardDAV;

use Sabre\DAV;
use Illuminate\Support\Arr;
use App\Models\User\SyncToken;
use App\Models\Contact\Contact;
use Sabre\VObject\Component\VCard;
Expand Down Expand Up @@ -330,7 +331,7 @@ public function updateCard($addressBookId, $cardUri, $cardData)
'behaviour' => ImportVCard::BEHAVIOUR_REPLACE,
]);

if (! array_has($result, 'error')) {
if (! Arr::has($result, 'error')) {
$contact = Contact::where('account_id', Auth::user()->account_id)
->find($result['contact_id']);
$card = $this->prepareCard($contact);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/DAV/DAVACL/PrincipalBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\DAV\DAVACL;

use Sabre\DAV;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Auth;
use Sabre\DAV\Server as SabreServer;
use Sabre\DAVACL\PrincipalBackend\AbstractBackend;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected function getPrincipals()
*/
public function getPrincipalsByPrefix($prefixPath)
{
$prefixPath = str_finish($prefixPath, '/');
$prefixPath = Str::finish($prefixPath, '/');

return array_filter($this->getPrincipals(), function ($principal) use ($prefixPath) {
return ! $prefixPath || strpos($principal['uri'], $prefixPath) == 0;
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\User\User;
use App\Helpers\DateHelper;
use App\Models\Contact\Tag;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Helpers\LocaleHelper;
use App\Helpers\RequestHelper;
Expand Down Expand Up @@ -369,7 +370,7 @@ public function inviteUser(InvitationRequest $request)
+ [
'invited_by_user_id' => auth()->user()->id,
'account_id' => auth()->user()->account_id,
'invitation_key' => str_random(100),
'invitation_key' => Str::random(100),
]
);

Expand Down
3 changes: 2 additions & 1 deletion app/Models/Account/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Contact\Tag;
use App\Models\Journal\Day;
use App\Models\User\Module;
use Illuminate\Support\Str;
use App\Models\Contact\Call;
use App\Models\Contact\Debt;
use App\Models\Contact\Gift;
Expand Down Expand Up @@ -864,7 +865,7 @@ public static function createDefault($first_name, $last_name, $email, $password,
{
// create new account
$account = new self;
$account->api_key = str_random(30);
$account->api_key = Str::random(30);
$account->created_at = now();
$account->save();

Expand Down
3 changes: 2 additions & 1 deletion app/Models/Account/ImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User\User;
use Sabre\VObject\Reader;
use Illuminate\Support\Arr;
use Sabre\VObject\Component\VCard;
use App\Services\VCard\ImportVCard;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -226,7 +227,7 @@ private function processSingleEntry($entry, $behaviour = ImportVCard::BEHAVIOUR_
return;
}

if (array_has($result, 'error') && ! empty($result['error'])) {
if (Arr::has($result, 'error') && ! empty($result['error'])) {
$this->skipEntry($result['name'], $result['reason']);

return;
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Call/CreateCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Contact\Call;

use Illuminate\Support\Arr;
use App\Models\Contact\Call;
use App\Services\BaseService;
use App\Models\Contact\Contact;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function execute(array $data) : Call
->findOrFail($data['contact_id']);

// emotions array is left out as they are not attached during this call
$call = Call::create(array_except($data, ['emotions']));
$call = Call::create(Arr::except($data, ['emotions']));

$this->updateLastCallInfo($contact, $call);

Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Contact/CreateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Contact\Contact;

use Illuminate\Support\Arr;
use App\Helpers\RandomHelper;
use App\Services\BaseService;
use App\Models\Contact\Contact;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function execute(array $data) : Contact
$this->validate($data);

// filter out the data that shall not be updated here
$dataOnly = array_except(
$dataOnly = Arr::except(
$data,
[
'is_birthdate_known',
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Contact/UpdateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Contact\Contact;

use Illuminate\Support\Arr;
use App\Services\BaseService;
use App\Models\Contact\Contact;

Expand Down Expand Up @@ -77,7 +78,7 @@ public function execute(array $data) : Contact
private function updateGeneralInformation(array $data, Contact $contact)
{
// filter out the data that shall not be updated here
$dataOnly = array_except(
$dataOnly = Arr::except(
$data,
[
'is_birthdate_known',
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Tag/AssociateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Services\Contact\Tag;

use App\Models\Contact\Tag;
use Illuminate\Support\Str;
use App\Helpers\LocaleHelper;
use App\Services\BaseService;
use App\Models\Contact\Contact;
Expand Down Expand Up @@ -75,7 +76,7 @@ private function createTag(array $data) : Tag
$array = [
'account_id' => $data['account_id'],
'name' => $data['name'],
'name_slug' => str_slug($data['name'], '-', LocaleHelper::getLang()),
'name_slug' => Str::slug($data['name'], '-', LocaleHelper::getLang()),
];

if (empty($array['name_slug'])) {
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Tag/CreateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Services\Contact\Tag;

use App\Models\Contact\Tag;
use Illuminate\Support\Str;
use App\Helpers\LocaleHelper;
use App\Services\BaseService;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function execute(array $data) : Tag
$array = [
'account_id' => $data['account_id'],
'name' => $data['name'],
'name_slug' => str_slug($data['name'], '-', LocaleHelper::getLang()),
'name_slug' => Str::slug($data['name'], '-', LocaleHelper::getLang()),
];

return Tag::create($array);
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Contact/Tag/UpdateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Services\Contact\Tag;

use App\Models\Contact\Tag;
use Illuminate\Support\Str;
use App\Helpers\LocaleHelper;
use App\Services\BaseService;

Expand Down Expand Up @@ -36,7 +37,7 @@ public function execute(array $data) : Tag
->findOrFail($data['tag_id']);

$tag->name = $data['name'];
$tag->name_slug = str_slug($data['name'], '-', LocaleHelper::getLang());
$tag->name_slug = Str::slug($data['name'], '-', LocaleHelper::getLang());
$tag->save();

return $tag;
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Instance/Geolocalization/GetGPSCoordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Instance\Geolocalization;

use Illuminate\Support\Str;
use App\Models\Account\Place;
use App\Services\BaseService;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -71,7 +72,7 @@ private function buildQuery(Place $place)
'q' => $place->getAddressAsString(),
]);

return str_finish(config('location.location_iq_url'), '/').'search.php?'.$query;
return Str::finish(config('location.location_iq_url'), '/').'search.php?'.$query;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Services/Instance/IdHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Instance;

use Illuminate\Support\Str;
use Vinkla\Hashids\Facades\Hashids;
use App\Exceptions\WrongIdException;

Expand Down Expand Up @@ -31,8 +32,8 @@ public function encodeId($id)

public function decodeId($hash)
{
if (starts_with($hash, $this->prefix)) {
$result = Hashids::decode(str_after($hash, $this->prefix));
if (Str::startsWith($hash, $this->prefix)) {
$result = Hashids::decode(Str::after($hash, $this->prefix));

if (count($result) > 0) {
return $result[0]; // result is always an array due to quirk in Hashids libary
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Instance/Weather/GetWeatherInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services\Instance\Weather;

use Illuminate\Support\Str;
use App\Models\Account\Place;
use App\Services\BaseService;
use App\Models\Account\Weather;
Expand Down Expand Up @@ -114,7 +115,7 @@ private function query(Place $place)
*/
private function buildQuery(Place $place)
{
$url = str_finish(config('location.darksky_url'), '/');
$url = Str::finish(config('location.darksky_url'), '/');
$key = config('monica.darksky_api_key');
$coords = $place->latitude.','.$place->longitude;

Expand Down
Loading