Skip to content

Commit

Permalink
Add style CI (#503)
Browse files Browse the repository at this point in the history
Hopefully this will result in slightly better code.
  • Loading branch information
djaiss committed Jul 27, 2017
1 parent 6127830 commit a2172f0
Show file tree
Hide file tree
Showing 148 changed files with 442 additions and 618 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
@@ -0,0 +1 @@
preset: laravel
22 changes: 10 additions & 12 deletions app/Account.php
Expand Up @@ -4,10 +4,9 @@

use DB;
use Laravel\Cashier\Billable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* @property User $user
Expand All @@ -27,7 +26,6 @@
*/
class Account extends Model
{

use Billable;

/**
Expand All @@ -36,7 +34,7 @@ class Account extends Model
* @var array
*/
protected $fillable = [
'number_of_invitations_sent', 'api_key'
'number_of_invitations_sent', 'api_key',
];

/**
Expand Down Expand Up @@ -210,7 +208,7 @@ public function tags()
}

/**
* Check if the account can be downgraded, based on a set of rules
* Check if the account can be downgraded, based on a set of rules.
*
* @return this
*/
Expand All @@ -234,9 +232,9 @@ public function canDowngrade()
}

/**
* Check if the account is currently subscribed to a plan
* Check if the account is currently subscribed to a plan.
*
* @return boolean $isSubscribed
* @return bool $isSubscribed
*/
public function isSubscribed()
{
Expand All @@ -254,7 +252,7 @@ public function isSubscribed()
* This was created because Laravel Cashier doesn't know how to properly
* handled the case when a user doesn't have invoices yet. This sucks balls.
*
* @return boolean
* @return bool
*/
public function hasInvoices()
{
Expand All @@ -267,16 +265,16 @@ public function hasInvoices()
}

/**
* Get the next billing date for the account
* Get the next billing date for the account.
*
* @return String $timestamp
* @return string $timestamp
*/
public function getNextBillingDate()
{
// Weird method to get the next billing date from Laravel Cashier
// see https://stackoverflow.com/questions/41576568/get-next-billing-date-from-laravel-cashier
$timestamp = $this->asStripeCustomer()["subscriptions"]
->data[0]["current_period_end"];
$timestamp = $this->asStripeCustomer()['subscriptions']
->data[0]['current_period_end'];

return \App\Helpers\DateHelper::getShortDate($timestamp);
}
Expand Down
4 changes: 1 addition & 3 deletions app/Activity.php
Expand Up @@ -2,8 +2,6 @@

namespace App;

use App\ActivityType;
use App\Helpers\DateHelper;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -74,7 +72,7 @@ public function type()
}

/**
* Get the date_it_happened field according to user's timezone
* Get the date_it_happened field according to user's timezone.
*
* @param string $value
* @return string
Expand Down
1 change: 0 additions & 1 deletion app/ActivityType.php
Expand Up @@ -2,7 +2,6 @@

namespace App;

use App\ActivityTypeGroup;
use Illuminate\Database\Eloquent\Model;

class ActivityType extends Model
Expand Down
1 change: 0 additions & 1 deletion app/Call.php
Expand Up @@ -2,7 +2,6 @@

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Expand Down
34 changes: 18 additions & 16 deletions app/Console/Commands/ImportCSV.php
Expand Up @@ -47,22 +47,24 @@ public function handle()
$user = User::where('email', $this->argument('user'))->first();
}

if (!file_exists($file)) {
if (! file_exists($file)) {
$this->error('You need to provide a valid file path.');

return -1;
}

if (!$user) {
if (! $user) {
$this->error('You need to provide a valid User ID or email address!');

return -1;
}

$this->info("Importing CSV file $file to user {$user->id}");

$row = 0;
$imported = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
if (($handle = fopen($file, 'r')) !== false) {
while (($data = fgetcsv($handle)) !== false) {
$row++;

// don't import the columns
Expand All @@ -78,51 +80,51 @@ public function handle()
continue;
}

if (!empty($data[1])) {
if (! empty($data[1])) {
$contact->first_name = $data[1]; // Given Name
}

if (!empty($data[2])) {
if (! empty($data[2])) {
$contact->middle_name = $data[2]; // Additional Name
}

if (!empty($data[3])) {
if (! empty($data[3])) {
$contact->last_name = $data[3]; // Family Name
}

if (!empty($data[14])) {
if (! empty($data[14])) {
$contact->birthdate = date('Y-m-d', strtotime($data[14]));
}

if (!empty($data[28])) {
if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}

if (!empty($data[42])) {
if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}

if (!empty($data[49])) {
if (! empty($data[49])) {
$contact->street = $data[49]; // address 1 street
}

if (!empty($data[50])) {
if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
}
if (!empty($data[52])) {
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
}

if (!empty($data[53])) {
if (! empty($data[53])) {
$contact->postal_code = $data[53]; // address 1 postal code (zip) 53
}
if (!empty($data[66])) {
if (! empty($data[66])) {
$contact->job = $data[66]; // organization 1 name 66
}

// can't have empty email
if (empty($contact->email)) {
$contact->email = NULL;
$contact->email = null;
}

$contact->save();
Expand Down
33 changes: 15 additions & 18 deletions app/Console/Commands/ImportVCards.php
Expand Up @@ -2,14 +2,13 @@

namespace App\Console\Commands;

use App\User;
use App\Contact;
use App\Country;
use App\User;
use Sabre\VObject\Reader;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\ICalendar\DateTime;
use Sabre\VObject\Reader;
use Illuminate\Filesystem\Filesystem;

class ImportVCards extends Command
{
Expand Down Expand Up @@ -45,16 +44,17 @@ public function __construct()
*/
public function handle(Filesystem $filesystem)
{
$path = './' . $this->argument('path');
$path = './'.$this->argument('path');

$user = User::where('email', $this->argument('user'))->first();

if (!$user) {
if (! $user) {
$this->error('You need to provide a valid user email!');

return;
}

if (!$filesystem->exists($path) || $filesystem->extension($path) !== 'vcf') {
if (! $filesystem->exists($path) || $filesystem->extension($path) !== 'vcf') {
$this->error('The provided vcard file was not found or is not valid!');

return;
Expand All @@ -65,7 +65,6 @@ public function handle(Filesystem $filesystem)
$this->info("We found {$matchCount} contacts in {$path}.");

if ($this->confirm('Would you like to import them?', true)) {

$this->info("Importing contacts from {$path}");

$this->output->progressStart($matchCount);
Expand All @@ -75,7 +74,6 @@ public function handle(Filesystem $filesystem)
collect($matches[0])->map(function ($vcard) {
return Reader::read($vcard);
})->each(function (VCard $vcard) use ($user, $skippedContacts) {

if ($this->contactExists($vcard, $user)) {
$this->output->progressAdvance();
$skippedContacts++;
Expand All @@ -94,7 +92,7 @@ public function handle(Filesystem $filesystem)
$contact = new Contact();
$contact->account_id = $user->account_id;

if($vcard->N && ! empty($vcard->N->getParts()[1])) {
if ($vcard->N && ! empty($vcard->N->getParts()[1])) {
$contact->first_name = $this->formatValue($vcard->N->getParts()[1]);
$contact->middle_name = $this->formatValue($vcard->N->getParts()[2]);
$contact->last_name = $this->formatValue($vcard->N->getParts()[0]);
Expand All @@ -105,14 +103,14 @@ public function handle(Filesystem $filesystem)
$contact->gender = 'none';
$contact->is_birthdate_approximate = 'unknown';

if ($vcard->BDAY && !empty((string) $vcard->BDAY)) {
if ($vcard->BDAY && ! empty((string) $vcard->BDAY)) {
$contact->birthdate = new \DateTime((string) $vcard->BDAY);
}

$contact->email = $this->formatValue($vcard->EMAIL);
$contact->phone_number = $this->formatValue($vcard->TEL);

if($vcard->ADR) {
if ($vcard->ADR) {
$contact->street = $this->formatValue($vcard->ADR->getParts()[2]);
$contact->city = $this->formatValue($vcard->ADR->getParts()[3]);
$contact->province = $this->formatValue($vcard->ADR->getParts()[4]);
Expand Down Expand Up @@ -142,22 +140,21 @@ public function handle(Filesystem $filesystem)

$this->info("Successfully imported {$matchCount} contacts and skipped {$skippedContacts}.");
}

}

/**
* Formats and returns a string for the contact
* Formats and returns a string for the contact.
*
* @param null|string $value
* @return null|string
*/
private function formatValue($value)
{
return !empty((string) $value) ? (string) $value : null;
return ! empty((string) $value) ? (string) $value : null;
}

/**
* Checks whether a contact already exists for a given account
* Checks whether a contact already exists for a given account.
*
* @param VCard $vcard
* @param User $user
Expand All @@ -169,7 +166,7 @@ private function contactExists(VCard $vcard, User $user)

$contact = Contact::where([
['account_id', $user->account_id],
['email', $email]
['email', $email],
])->first();

return $email && $contact;
Expand All @@ -182,7 +179,7 @@ private function contactExists(VCard $vcard, User $user)
* @param VCard $vcard
* @return bool
*/
function contactHasName(VCard $vcard): bool
public function contactHasName(VCard $vcard): bool
{
return ! empty($vcard->N->getParts()[1]) || ! empty((string) $vcard->NICKNAME);
}
Expand Down
13 changes: 6 additions & 7 deletions app/Console/Commands/PingVersionServer.php
Expand Up @@ -2,11 +2,10 @@

namespace App\Console\Commands;

use Log;
use App\Contact;
use App\Instance;
use Illuminate\Console\Command;
use GuzzleHttp\Client;
use Illuminate\Console\Command;

class PingVersionServer extends Command
{
Expand Down Expand Up @@ -55,18 +54,18 @@ public function handle()
$json = [
'uuid' => $instance->uuid,
'version' => $instance->current_version,
'contacts' => Contact::count()
'contacts' => Contact::count(),
];

$data["uuid"] = $instance->uuid;
$data["version"] = $instance->current_version;
$data["contacts"] = Contact::all()->count();
$data['uuid'] = $instance->uuid;
$data['version'] = $instance->current_version;
$data['contacts'] = Contact::all()->count();

// Send the JSON
try {
$client = new Client();
$response = $client->post(config('monica.weekly_ping_server_url'), [
'json' => $data
'json' => $data,
]);
} catch (\GuzzleHttp\Exception\ConnectException $e) {
return;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ResetTestDB.php
Expand Up @@ -39,7 +39,7 @@ public function __construct()
public function handle()
{
if (config('app.env') == 'local') {
foreach(\DB::select('SHOW TABLES') as $table) {
foreach (\DB::select('SHOW TABLES') as $table) {
$table_array = get_object_vars($table);
\Schema::drop($table_array[key($table_array)]);
}
Expand Down
2 changes: 0 additions & 2 deletions app/Console/Commands/SendNotifications.php
Expand Up @@ -2,10 +2,8 @@

namespace App\Console\Commands;

use Log;
use App\User;
use App\Account;
use App\Contact;
use App\Reminder;
use Carbon\Carbon;
use App\Jobs\SendReminderEmail;
Expand Down

0 comments on commit a2172f0

Please sign in to comment.