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

fix for several problems pointed by larastan level 0 #3776

Closed
wants to merge 2 commits into from
Closed
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
204 changes: 99 additions & 105 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,40 @@ protected function configureDatabase(array $default = [])
'DB_PREFIX' => null,
], $default);

$config['DB_DRIVER'] = $this->choice('Which database driver do you want to use?', [
'mysql' => 'MySQL',
'pgsql' => 'PostgreSQL',
'sqlite' => 'SQLite',
], $config['DB_DRIVER']);

if ($config['DB_DRIVER'] === 'sqlite') {
$config['DB_DATABASE'] = $this->ask('Please provide the full path to your SQLite file.', $config['DB_DATABASE']);
} else {
$config['DB_HOST'] = $this->ask("What is the host of your {$config['DB_DRIVER']} database?", $config['DB_HOST']);
if ($config['DB_HOST'] === 'localhost' && $config['DB_DRIVER'] === 'mysql') {
$this->warn("Using 'localhost' will result in the usage of a local unix socket. Use 127.0.0.1 if you want to connect over TCP");
do {
$config['DB_DRIVER'] = $this->choice('Which database driver do you want to use?', [
'mysql' => 'MySQL',
'pgsql' => 'PostgreSQL',
'sqlite' => 'SQLite',
], $config['DB_DRIVER']);

if ($config['DB_DRIVER'] === 'sqlite') {
$config['DB_DATABASE'] = $this->ask('Please provide the full path to your SQLite file.', $config['DB_DATABASE']);
} else {
$config['DB_HOST'] = $this->ask("What is the host of your {$config['DB_DRIVER']} database?", $config['DB_HOST']);
if ($config['DB_HOST'] === 'localhost' && $config['DB_DRIVER'] === 'mysql') {
$this->warn("Using 'localhost' will result in the usage of a local unix socket. Use 127.0.0.1 if you want to connect over TCP");
}

$config['DB_DATABASE'] = $this->ask('What is the name of the database that Cachet should use?', $config['DB_DATABASE']);

$config['DB_USERNAME'] = $this->ask('What username should we connect with?', $config['DB_USERNAME']);

$config['DB_PASSWORD'] = $this->secret('What password should we connect with?', $config['DB_PASSWORD']);

$config['DB_PORT'] = $config['DB_DRIVER'] === 'mysql' ? 3306 : 5432;
if ($this->confirm('Is your database listening on a non-standard port number?')) {
$config['DB_PORT'] = $this->anticipate('What port number is your database using?', [3306, 5432], $config['DB_PORT']);
}
}

$config['DB_DATABASE'] = $this->ask('What is the name of the database that Cachet should use?', $config['DB_DATABASE']);

$config['DB_USERNAME'] = $this->ask('What username should we connect with?', $config['DB_USERNAME']);

$config['DB_PASSWORD'] = $this->secret('What password should we connect with?', $config['DB_PASSWORD']);

$config['DB_PORT'] = $config['DB_DRIVER'] === 'mysql' ? 3306 : 5432;
if ($this->confirm('Is your database listening on a non-standard port number?')) {
$config['DB_PORT'] = $this->anticipate('What port number is your database using?', [3306, 5432], $config['DB_PORT']);
if ($this->confirm('Do you want to use a prefix on the table names?')) {
$config['DB_PREFIX'] = $this->ask('Please enter the prefix now...', $config['DB_PREFIX']);
}
}

if ($this->confirm('Do you want to use a prefix on the table names?')) {
$config['DB_PREFIX'] = $this->ask('Please enter the prefix now...', $config['DB_PREFIX']);
}

// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);

if (!$this->confirm('Are these settings correct?')) {
return $this->configureDatabase($config);
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
} while (!$this->confirm('Are these settings correct?'));

foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
Expand All @@ -198,57 +196,55 @@ protected function configureDrivers(array $default = [])
'QUEUE_DRIVER' => null,
], $default);

// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);

$config['CACHE_DRIVER'] = $this->choice('Which cache driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['CACHE_DRIVER']);

// We need to configure Redis.
if ($config['CACHE_DRIVER'] === 'redis') {
$this->configureRedis();
}

$config['SESSION_DRIVER'] = $this->choice('Which session driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['SESSION_DRIVER']);

// We need to configure Redis.
if ($config['SESSION_DRIVER'] === 'redis') {
$this->configureRedis();
}
do {
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);

$config['CACHE_DRIVER'] = $this->choice('Which cache driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['CACHE_DRIVER']);

// We need to configure Redis.
if ($config['CACHE_DRIVER'] === 'redis') {
$this->configureRedis();
}

$config['QUEUE_DRIVER'] = $this->choice('Which queue driver do you want to use?', [
'null' => 'None',
'sync' => 'Synchronous',
'database' => 'Database',
'beanstalkd' => 'Beanstalk',
'sqs' => 'Amazon SQS',
'redis' => 'Redis',
], $config['QUEUE_DRIVER']);

// We need to configure Redis, but only if the cache driver wasn't redis.
if ($config['QUEUE_DRIVER'] === 'redis' && ($config['SESSION_DRIVER'] !== 'redis' || $config['CACHE_DRIVER'] !== 'redis')) {
$this->configureRedis();
}
$config['SESSION_DRIVER'] = $this->choice('Which session driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['SESSION_DRIVER']);

// We need to configure Redis.
if ($config['SESSION_DRIVER'] === 'redis') {
$this->configureRedis();
}

// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
$config['QUEUE_DRIVER'] = $this->choice('Which queue driver do you want to use?', [
'null' => 'None',
'sync' => 'Synchronous',
'database' => 'Database',
'beanstalkd' => 'Beanstalk',
'sqs' => 'Amazon SQS',
'redis' => 'Redis',
], $config['QUEUE_DRIVER']);

// We need to configure Redis, but only if the cache driver wasn't redis.
if ($config['QUEUE_DRIVER'] === 'redis' && ($config['SESSION_DRIVER'] !== 'redis' || $config['CACHE_DRIVER'] !== 'redis')) {
$this->configureRedis();
}

if (!$this->confirm('Are these settings correct?')) {
return $this->configureDrivers($config);
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
} while (!$this->confirm('Are these settings correct?'));

foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
Expand Down Expand Up @@ -280,33 +276,31 @@ protected function configureMail(array $config = [])
return;
}

$config['MAIL_DRIVER'] = $this->choice('What driver do you want to use to send notifications?', [
'smtp' => 'SMTP',
'mail' => 'Mail',
'sendmail' => 'Sendmail',
'mailgun' => 'Mailgun',
'mandrill' => 'Mandrill',
'ses' => 'Amazon SES',
'sparkpost' => 'SparkPost',
'log' => 'Log (Testing)',
]);

if (!$config['MAIL_DRIVER'] === 'log') {
if ($config['MAIL_DRIVER'] === 'smtp') {
$config['MAIL_HOST'] = $this->ask('Please supply your mail server host');
do {
$config['MAIL_DRIVER'] = $this->choice('What driver do you want to use to send notifications?', [
'smtp' => 'SMTP',
'mail' => 'Mail',
'sendmail' => 'Sendmail',
'mailgun' => 'Mailgun',
'mandrill' => 'Mandrill',
'ses' => 'Amazon SES',
'sparkpost' => 'SparkPost',
'log' => 'Log (Testing)',
]);

if (!$config['MAIL_DRIVER'] === 'log') {
if ($config['MAIL_DRIVER'] === 'smtp') {
$config['MAIL_HOST'] = $this->ask('Please supply your mail server host');
}

$config['MAIL_ADDRESS'] = $this->ask('What email address should we send notifications from?');
$config['MAIL_USERNAME'] = $this->ask('What username should we connect as?');
$config['MAIL_PASSWORD'] = $this->secret('What password should we connect with?');
}

$config['MAIL_ADDRESS'] = $this->ask('What email address should we send notifications from?');
$config['MAIL_USERNAME'] = $this->ask('What username should we connect as?');
$config['MAIL_PASSWORD'] = $this->secret('What password should we connect with?');
}

// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);

if (!$this->confirm('Are these settings correct?')) {
return $this->configureMail($config);
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
} while (!$this->confirm('Are these settings correct?'));

foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(Feed $feed, Guard $guard)
$this->feed = $feed;
$this->guard = $guard;
$this->startDate = new Date();
$this->dateTimeZone = Config::get('cachet.timezone');
$this->timeZone = Config::get('cachet.timezone');
}

/**
Expand Down Expand Up @@ -134,12 +134,12 @@ protected function getIncidents()
$this->startDate->format('Y-m-d').' 23:59:59',
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
return (new Date($incident->occurred_at))
->setTimezone($this->dateTimeZone)->toDateString();
->setTimezone($this->timeZone)->toDateString();
});

// Add in days that have no incidents
foreach (range(0, 30) as $i) {
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
$date = (new Date($this->startDate))->setTimezone($this->timeZone)->subDays($i);

if (!isset($allIncidents[$date->toDateString()])) {
$allIncidents[$date->toDateString()] = [];
Expand All @@ -166,12 +166,12 @@ protected function getSubscribers()
$this->startDate->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $incident) {
return (new Date($incident->created_at))
->setTimezone($this->dateTimeZone)->toDateString();
->setTimezone($this->timeZone)->toDateString();
});

// Add in days that have no incidents
foreach (range(0, 30) as $i) {
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
$date = (new Date($this->startDate))->setTimezone($this->timeZone)->subDays($i);

if (!isset($allSubscribers[$date->toDateString()])) {
$allSubscribers[$date->toDateString()] = [];
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Middleware/RemoteUserAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

class RemoteUserAuthenticate
{
/**
* The auth guard instance.
*
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;

/**
* Create a new remote user authenticate instance.
*
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Http\Middleware;

use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

Expand Down Expand Up @@ -41,8 +42,10 @@ class TrustProxies extends Middleware
*
* @return void
*/
public function __construct()
public function __construct(Repository $config)
{
parent::__construct($config);

$proxies = Config::get('trustedproxies.proxies');

$this->proxies = empty($proxies) ? '*' : explode(',', trim($proxies));
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function scopeIsVerifiedForComponent(Builder $query, $component_id)
{
return $query->select('subscriptions.*')
->join('subscribers', 'subscriptions.subscriber_id', '=', 'subscribers.id')
->where(function ($query) {
->where(function ($query) use ($component_id) {
$query->where('subscriptions.component_id', '=', $component_id)
->orWhere('subscribers.global');
})
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/Incident/NewIncidentNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function toSlack($notifiable)
return (new SlackMessage())
->$status()
->content($content)
->attachment(function ($attachment) use ($notifiable) {
->attachment(function ($attachment) {
$attachment->title(trans('notifications.incident.new.slack.title', ['name' => $this->incident->name]))
->timestamp($this->incident->getWrappedObject()->occurred_at)
->fields(array_filter([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function toSlack($notifiable)
return (new SlackMessage())
->$status()
->content($content)
->attachment(function ($attachment) use ($content, $notifiable) {
->attachment(function ($attachment) use ($notifiable) {
$attachment->title(trans('notifications.incident.update.slack.title', [
'name' => $this->update->incident->name,
'new_status' => $this->update->human_status,
Expand Down
4 changes: 1 addition & 3 deletions app/Presenters/IncidentPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CachetHQ\Cachet\Presenters;

use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use CachetHQ\Cachet\Services\Dates\DateFactory;
use GrahamCampbell\Markdown\Facades\Markdown;
Expand Down Expand Up @@ -53,11 +52,10 @@ class IncidentPresenter extends BasePresenter implements Arrayable
* Create a new presenter.
*
* @param \CachetHQ\Cachet\Services\Dates\DateFactory $dates
* @param \CachetHQ\Cachet\Models\Incident $resource
*
* @return void
*/
public function __construct(DateFactory $dates, Incident $resource)
public function __construct(DateFactory $dates)
{
$this->dates = $dates;
}
Expand Down
3 changes: 1 addition & 2 deletions app/Presenters/SchedulePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ class SchedulePresenter extends BasePresenter implements Arrayable
* Create a new presenter.
*
* @param \CachetHQ\Cachet\Services\Dates\DateFactory $dates
* @param \CachetHQ\Cachet\Models\Schedule $resource
*
* @return void
*/
public function __construct(DateFactory $dates, Schedule $resource)
public function __construct(DateFactory $dates)
{
$this->dates = $dates;
}
Expand Down
2 changes: 1 addition & 1 deletion app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function cachet_redirect($name, $parameters = [], $status = 302, $headers = [],
*
* @param object $command
*
* @return void
* @return mixed
*/
function execute($command)
{
Expand Down