Skip to content

Commit

Permalink
chore: add thecodingmachine/safe package (monicahq#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored May 4, 2019
1 parent 7827057 commit aa75e7d
Show file tree
Hide file tree
Showing 44 changed files with 368 additions and 55 deletions.
39 changes: 20 additions & 19 deletions app/Console/Commands/ImportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Console\Commands;

use function Safe\fopen;
use App\Models\User\User;
use function Safe\fclose;
use App\Helpers\DateHelper;
use App\Models\Contact\Gender;
use App\Models\Contact\Address;
Expand Down Expand Up @@ -87,27 +89,26 @@ public function handle()

$first = true;
$imported = 0;
if (($handle = fopen($file, 'r')) !== false) {
try {
while (($data = fgetcsv($handle)) !== false) {
// don't import the columns
if ($first) {
$first = false;
continue;
}

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
continue;
}

$this->csvToContact($data, $user->account_id, $gender->id);

$imported++;
try {
$handle = fopen($file, 'r');
while (($data = fgetcsv($handle)) !== false) {
// don't import the columns
if ($first) {
$first = false;
continue;
}
} finally {
fclose($handle);

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
continue;
}

$this->csvToContact($data, $user->account_id, $gender->id);

$imported++;
}
} finally {
fclose($handle);
}

$this->info("Imported {$imported} Contacts");
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/PingVersionServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use GuzzleHttp\Client;
use function Safe\json_decode;
use App\Models\Contact\Contact;
use Illuminate\Console\Command;
use App\Models\Instance\Instance;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/SentryRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Console\Commands;

use function Safe\mkdir;
use Illuminate\Console\Command;
use function Safe\file_put_contents;
use Illuminate\Console\ConfirmableTrait;
use App\Console\Commands\Helpers\CommandExecutor;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/SetupProduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use function Safe\touch;
use App\Models\Account\Account;
use Illuminate\Console\Command;

Expand Down
2 changes: 2 additions & 0 deletions app/Helpers/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Helpers;

use function Safe\unlink;

class ComposerScripts
{
const CONFIG = 'bootstrap/cache/config.php';
Expand Down
1 change: 1 addition & 0 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Jenssegers\Date\Date;
use function Safe\strtotime;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;

Expand Down
2 changes: 2 additions & 0 deletions app/Helpers/InstanceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Helpers;

use function Safe\json_decode;
use App\Models\Account\Account;
use function Safe\file_get_contents;

class InstanceHelper
{
Expand Down
2 changes: 2 additions & 0 deletions app/Helpers/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Arr;
use Matriphe\ISO639\ISO639;
use function Safe\preg_match;
use function Safe\preg_split;
use Illuminate\Support\Facades\App;
use libphonenumber\PhoneNumberUtil;
use Illuminate\Support\Facades\Auth;
Expand Down
1 change: 1 addition & 0 deletions app/Helpers/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use function Safe\preg_match;
use App\Models\Contact\Contact;
use Illuminate\Support\Facades\Auth;
use App\Models\Contact\ContactFieldType;
Expand Down
1 change: 1 addition & 0 deletions 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 function Safe\substr;
use Illuminate\Support\Arr;

class TimezoneHelper
Expand Down
16 changes: 11 additions & 5 deletions app/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers\Api;

use function Safe\substr;
use Illuminate\Http\Request;
use function Safe\json_decode;
use App\Models\Account\ApiUsage;
use App\Http\Controllers\Controller;
use App\Traits\JsonRespondController;
Expand Down Expand Up @@ -65,11 +67,15 @@ public function __construct()
// if the call contains a JSON, the call must not be a GET or
// a DELETE
// TODO: there is probably a much better way to do that
if ($request->method() != 'GET' && $request->method() != 'DELETE'
&& is_null(json_decode($request->getContent()))) {
return $this->setHTTPStatusCode(400)
->setErrorCode(37)
->respondWithError();
try {
if ($request->method() != 'GET' && $request->method() != 'DELETE'
&& is_null(json_decode($request->getContent()))) {
return $this->setHTTPStatusCode(400)
->setErrorCode(37)
->respondWithError();
}
} catch (\Safe\Exceptions\JsonException $e) {
// no error
}

return $next($request);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/Auth/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client;
use App\Models\User\User;
use Illuminate\Http\Request;
use function Safe\json_decode;
use Illuminate\Support\Facades\App;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Helpers\DateHelper;
use App\Models\Contact\Debt;
use Illuminate\Http\Request;
use function Safe\json_encode;
use App\Helpers\InstanceHelper;
use App\Models\Contact\Contact;
use Illuminate\Support\Collection;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Settings/MultiFAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Settings;

use Illuminate\Http\Request;
use function Safe\json_decode;
use Lahaxearnaud\U2f\Models\U2fKey;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
Expand Down
6 changes: 5 additions & 1 deletion app/Models/Account/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models\Account;

use App\Models\Contact\Contact;
use function Safe\preg_replace;
use App\Helpers\CountriesHelper;
use App\Models\ModelBinding as Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -83,7 +84,10 @@ public function getAddressAsString()
}

// trim extra whitespaces inside the address
return preg_replace('/\s+/', ' ', $address);
$address = preg_replace('/\s+/', ' ', $address);
if (is_string($address)) {
return $address;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\Account\Account;
use App\Models\Account\Weather;
use App\Models\Account\Activity;
use function Safe\preg_match_all;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use App\Models\Instance\SpecialDate;
Expand Down
1 change: 1 addition & 0 deletions app/Services/Instance/Geolocalization/GetGPSCoordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Str;
use App\Models\Account\Place;
use App\Services\BaseService;
use function Safe\json_decode;
use Illuminate\Support\Facades\Log;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
Expand Down
1 change: 1 addition & 0 deletions app/Services/Instance/Weather/GetWeatherInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Str;
use App\Models\Account\Place;
use App\Services\BaseService;
use function Safe\json_decode;
use App\Models\Account\Weather;
use Illuminate\Support\Facades\Log;
use GuzzleHttp\Client as GuzzleClient;
Expand Down
2 changes: 2 additions & 0 deletions app/Services/VCard/ImportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Ramsey\Uuid\Uuid;
use App\Models\User\User;
use App\Traits\DAVFormat;
use function Safe\substr;
use Sabre\VObject\Reader;
use App\Helpers\DateHelper;
use Illuminate\Support\Arr;
Expand All @@ -13,6 +14,7 @@
use App\Helpers\LocaleHelper;
use App\Helpers\RandomHelper;
use App\Services\BaseService;
use function Safe\preg_split;
use App\Models\Contact\Gender;
use App\Models\Contact\Address;
use App\Models\Contact\Contact;
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"sentry/sentry-laravel": "^1.0",
"stevebauman/location": "^3.0",
"symfony/translation": "^4.0",
"thecodingmachine/safe": "^0.1.15",
"vectorface/whip": "^0.3.2",
"vinkla/hashids": "^6.0",
"vluzrmos/language-detector": "^1.0"
Expand All @@ -63,6 +64,7 @@
"roave/security-advisories": "dev-master",
"symfony/css-selector": "~4.0",
"symfony/dom-crawler": "~4.0",
"thecodingmachine/phpstan-safe-rule": "^0.1.3",
"vimeo/psalm": "^3.0"
},
"suggest": {
Expand Down
Loading

0 comments on commit aa75e7d

Please sign in to comment.