Skip to content

Commit

Permalink
Merge branch 'release/4.1.27'
Browse files Browse the repository at this point in the history
* release/4.1.27:
  updated the changelog
  compiled assets
  Apply fixes from StyleCI (#463)
  work
  Apply fixes from StyleCI (#461)
  reduce redundancy, handle resources in service provider's boot() method
  compile assets
  • Loading branch information
austintoddj committed Apr 17, 2019
2 parents ade2b21 + 0ba16b9 commit 6bcbd01
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 107 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## [v4.1.27](https://github.com/cnvs/canvas/compare/v4.1.26...v4.1.27)

### Changed
- Refactored resource handling from the `register()` to the `boot()` method in the service provider ([#462](https://github.com/cnvs/canvas/pull/462))

## [v4.1.26](https://github.com/cnvs/canvas/compare/v4.1.25...v4.1.26)

### Added
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
"illuminate/support": "~5.8.0|~5.9.0",
"illuminate/contracts": "~5.8.0|~5.9.0"
"illuminate/support": "~5.8.0"
},
"require-dev": {
"mockery/mockery": "^1.1",
Expand Down
2 changes: 1 addition & 1 deletion public/css/app-dark.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"/js/app.js": "/js/app.js?id=40512207b246203d2129",
"/css/app.css": "/css/app.css?id=30702a620a23ba741c32",
"/css/app-dark.css": "/css/app-dark.css?id=ceb9852370c32c15e835",
"/js/app.js.map": "/js/app.js.map?id=641d82a0e2d575c8fac7",
"/js/app.js": "/js/app.js?id=ccc5d6c6548239847e20",
"/css/app.css": "/css/app.css?id=f67fa09e4165d6153c77",
"/css/app-dark.css": "/css/app-dark.css?id=96b402438f4da22bea87",
"/js/app.js.map": "/js/app.js.map?id=622c991d455e028e478f",
"/favicon.ico": "/favicon.ico?id=dbb0c05daa3432643753"
}
61 changes: 40 additions & 21 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,23 @@ class CanvasServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->registerEvents();
$this->registerRoutes();
$this->registerMigrations();
$this->registerPublishing();
$this->registerResources();
$this->handleConfig();
$this->handleEvents();
$this->handleRoutes();
$this->handleMigrations();
$this->handlePublishing();
$this->handleResources();
$this->handleCommands();
}

/**
* Register any package services.
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../config/canvas.php', 'canvas'
);

$this->commands([
InstallCommand::class,
PublishCommand::class,
SetupCommand::class,
]);
//
}

/**
Expand All @@ -53,7 +47,7 @@ public function register()
* @return void
* @throws BindingResolutionException
*/
private function registerEvents()
private function handleEvents()
{
$events = $this->app->make(Dispatcher::class);

Expand All @@ -69,7 +63,7 @@ private function registerEvents()
*
* @return void
*/
private function registerRoutes()
private function handleRoutes()
{
Route::group($this->routeConfiguration(), function () {
$this->loadRoutesFrom(__DIR__.'/../routes/canvas.php');
Expand All @@ -95,7 +89,7 @@ private function routeConfiguration()
*
* @return void
*/
private function registerResources()
private function handleResources()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'canvas');
}
Expand All @@ -105,7 +99,7 @@ private function registerResources()
*
* @return void
*/
private function registerMigrations()
private function handleMigrations()
{
if ($this->app->runningInConsole()) {
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
Expand All @@ -117,7 +111,7 @@ private function registerMigrations()
*
* @return void
*/
private function registerPublishing()
private function handlePublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand All @@ -129,8 +123,33 @@ private function registerPublishing()
], 'canvas-config');

$this->publishes([
__DIR__.'/../stubs/providers/CanvasServiceProvider.stub' => app_path('Providers/CanvasServiceProvider.php'),
__DIR__.'/../stubs/providers/CanvasServiceProvider.stub' => app_path(
'Providers/CanvasServiceProvider.php'
),
], 'canvas-provider');
}
}

/**
* @return void
*/
private function handleConfig(): void
{
$this->mergeConfigFrom(
__DIR__.'/../config/canvas.php',
'canvas'
);
}

/**
* @return void
*/
private function handleCommands(): void
{
$this->commands([
InstallCommand::class,
PublishCommand::class,
SetupCommand::class,
]);
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StatsController extends Controller
*
* @const int
*/
const DAYS_PRIOR = 30;
private const DAYS_PRIOR = 30;

/**
* Get all of the posts and views.
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/ViewThrottle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ViewThrottle
*
* @const int
*/
const EXPIRES_IN = 3600;
private const EXPIRES_IN = 3600;

/**
* Handle the incoming request.
Expand Down
28 changes: 12 additions & 16 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,19 @@ public function views(): HasMany
/**
* Get the user who authored the post.
*
* @param $value
* @return User
*/
public function getAuthorAttribute($value): User
public function getAuthorAttribute(): User
{
return User::find($this->user_id);
return $this->user;
}

/**
* Check to see if the post is published.
*
* @param $value
* @return bool
*/
public function getPublishedAttribute($value): bool
public function getPublishedAttribute(): bool
{
if ($this->published_at <= now()->toDateTimeString()) {
return true;
Expand All @@ -146,10 +144,9 @@ public function getPublishedAttribute($value): bool
/**
* Get the human-friendly estimated reading time of a post.
*
* @param $value
* @return string
*/
public function getReadTimeAttribute($value): string
public function getReadTimeAttribute(): string
{
// Only count words in our estimation
$words = str_word_count(strip_tags($this->body));
Expand All @@ -163,13 +160,12 @@ public function getReadTimeAttribute($value): string
/**
* Get the 10 most popular reading times rounded to the nearest 30 minutes.
*
* @param $value
* @return array
*/
public function getPopularReadingTimesAttribute($value): array
public function getPopularReadingTimesAttribute(): array
{
// Get the views associated with the post
$data = View::where('post_id', $this->id)->get();
$data = $this->views;

// Filter the view data to only include hours:minutes
$collection = collect();
Expand All @@ -182,7 +178,6 @@ public function getPopularReadingTimesAttribute($value): array

$popular_reading_times = collect();
foreach ($filtered as $key => $value) {

// Use each given time to create a 60 min range
$start_time = Carbon::createFromTimeString($key);
$end_time = $start_time->copy()->addMinutes(60);
Expand All @@ -191,7 +186,10 @@ public function getPopularReadingTimesAttribute($value): array
$percentage = number_format($value / $data->count() * 100, 2);

// Get a human-readable hour range and floating percentage
$popular_reading_times->put(sprintf('%s - %s', $start_time->format('g:i A'), $end_time->format('g:i A')), $percentage);
$popular_reading_times->put(
sprintf('%s - %s', $start_time->format('g:i A'), $end_time->format('g:i A')),
$percentage
);
}

// Cast the collection to an array
Expand All @@ -209,10 +207,9 @@ public function getPopularReadingTimesAttribute($value): array
/**
* Get the top 10 referring websites for a post.
*
* @param $value
* @return array
*/
public function getTopReferersAttribute($value): array
public function getTopReferersAttribute(): array
{
// Get the views associated with the post
$data = $this->views;
Expand All @@ -238,10 +235,9 @@ public function getTopReferersAttribute($value): array
/**
* Return a view count for the last 30 days.
*
* @param $value
* @return array
*/
public function getViewTrendAttribute($value): array
public function getViewTrendAttribute(): array
{
// Get the views associated with the post
$data = $this->views;
Expand Down
Loading

0 comments on commit 6bcbd01

Please sign in to comment.