Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Oct 6, 2017
2 parents 5f2993c + 0a1d2f7 commit 3da74c4
Show file tree
Hide file tree
Showing 42 changed files with 261 additions and 222 deletions.
63 changes: 36 additions & 27 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('files')
->exclude('vendor')
->in(__DIR__);
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
/**
* symfony
*/
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
'blankline_after_open_tag',
'blank_line_after_opening_tag' => true,
// Remove duplicated semicolons.
'duplicate_semicolon',
// Removes extra empty lines.
'extra_empty_lines',
'no_empty_statement' => true,
// PHP multi-line arrays should have a trailing comma.
'multiline_array_trailing_comma',
'trailing_comma_in_multiline_array' => true,
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening',
'no_blank_lines_after_class_opening' => true,
// There should not be blank lines between docblock and the documented element.
'no_empty_lines_after_phpdocs',
'no_blank_lines_after_phpdoc' => true,
// Phpdocs short descriptions should end in either a full stop, exclamation mark, or question mark.
'phpdoc_short_description',
'phpdoc_summary' => true,
// Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim',
'phpdoc_trim' => true,
// Removes line breaks between use statements.
'remove_lines_between_uses',
'no_extra_consecutive_blank_lines' => ['use'],
// An empty line feed should precede a return statement.
'return',
'blank_line_before_return' => true,
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace',
'single_blank_line_before_namespace' => true,
// Convert double quotes to single quotes for simple strings.
'single_quote',
'single_quote' => true,
// Unused use statements must be removed.
'unused_use',
'no_unused_imports' => true,
// Methods must be separated with one blank line.
'method_separation' => true,
// Binary operators should be surrounded by at least one space.
'binary_operator_spaces' => ['align_double_arrow' => false],
// A single space should be between cast and variable.
'cast_spaces' => true,

/**
* contrib
*/
// Concatenation should be used with at least one whitespace around.
'concat_with_spaces',
// Ensure there is no code on the same line as the PHP open tag.
'newline_after_open_tag',
'concat_space' => ['spacing' => 'one'],
// Ordering use statements.
'ordered_use',
'ordered_imports' => true,
// PHP arrays should be declared using the configured syntax.
'array_syntax' => ['syntax' => 'short']
])
->setUsingCache(true)
->finder($finder);
->setFinder(
PhpCsFixer\Finder::create()
->exclude('files')
->exclude('vendor')
->in(__DIR__)
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
)
->setUsingCache(true);
8 changes: 4 additions & 4 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
filter:
excluded_paths:
- 'tests/*'
- 'src/Cmgmyr/Messenger/examples/'
- 'src/config/'
- 'src/migrations/'
- 'examples/*'
- 'config/*'
- 'migrations/*'

checks:
php:
Expand All @@ -24,4 +24,4 @@ checks:
tools:
external_code_coverage:
timeout: 1800
runs: 4
runs: 3
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand All @@ -17,6 +16,7 @@ cache:

before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
- composer dumpautoload -o

script:
- vendor/bin/php-cs-fixer fix .
Expand Down
20 changes: 15 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=5.5.0",
"illuminate/config": "~5.0",
"illuminate/support": "~5.0",
"illuminate/database": "~5.0",
"nesbot/carbon": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"adamwathan/faktory": "0.3.*",
"friendsofphp/php-cs-fixer": "^1.11",
"orchestra/testbench": "~3.0"
"friendsofphp/php-cs-fixer": "^2.5",
"orchestra/testbench": "~3.0",
"phpunit/phpunit": "4.*|5.*"
},
"autoload": {
"psr-0": {
"psr-4": {
"Cmgmyr\\Messenger\\": "src/"
}
},
Expand All @@ -34,5 +34,15 @@
"Cmgmyr\\Messenger\\Test\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Cmgmyr\\Messenger\\MessengerServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "stable"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function show($id)
} catch (ModelNotFoundException $e) {
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');

return redirect('messages');
return redirect()->route('messages');
}

// show current user in list if not a current participant
// $users = User::whereNotIn('id', $thread->participantsUserIds())->get();

// don't show the current user in list
$userId = Auth::user()->id;
$userId = Auth::id();
$users = User::whereNotIn('id', $thread->participantsUserIds($userId))->get();

$thread->markAsRead($userId);
Expand Down Expand Up @@ -82,36 +82,30 @@ public function store()
{
$input = Input::all();

$thread = Thread::create(
[
'subject' => $input['subject'],
]
);
$thread = Thread::create([
'subject' => $input['subject'],
]);

// Message
Message::create(
[
'thread_id' => $thread->id,
'user_id' => Auth::user()->id,
'body' => $input['message'],
]
);
Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => $input['message'],
]);

// Sender
Participant::create(
[
'thread_id' => $thread->id,
'user_id' => Auth::user()->id,
'last_read' => new Carbon,
]
);
Participant::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'last_read' => new Carbon,
]);

// Recipients
if (Input::has('recipients')) {
$thread->addParticipant($input['recipients']);
}

return redirect('messages');
return redirect()->route('messages');
}

/**
Expand All @@ -127,27 +121,23 @@ public function update($id)
} catch (ModelNotFoundException $e) {
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');

return redirect('messages');
return redirect()->route('messages');
}

$thread->activateAllParticipants();

// Message
Message::create(
[
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => Input::get('message'),
]
);
Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'body' => Input::get('message'),
]);

// Add replier as a participant
$participant = Participant::firstOrCreate(
[
'thread_id' => $thread->id,
'user_id' => Auth::user()->id,
]
);
$participant = Participant::firstOrCreate([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
]);
$participant->last_read = new Carbon;
$participant->save();

Expand All @@ -156,6 +146,6 @@ public function update($id)
$thread->addParticipant(Input::get('recipients'));
}

return redirect('messages/' . $id);
return redirect()->route('messages.show', $id);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Messenger (L5.3)</a>
<a class="navbar-brand" href="#">Messenger</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function up()
*/
public function down()
{
Schema::drop(Models::table('threads'));
Schema::dropIfExists(Models::table('threads'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function up()
*/
public function down()
{
Schema::drop(Models::table('messages'));
Schema::dropIfExists(Models::table('messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function up()
*/
public function down()
{
Schema::drop(Models::table('participants'));
Schema::dropIfExists(Models::table('participants'));
}
}
7 changes: 2 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
</php>
<filter>
<whitelist>
<directory suffix=".php">src/Cmgmyr</directory>
<directory suffix=".php">src</directory>
<exclude>
<directory>src/migrations/</directory>
<directory>src/config/</directory>
<directory>src/Cmgmyr/Messenger/examples/</directory>
<file>src/Cmgmyr/Messenger/MessengerServiceProvider.php</file>
<file>src/MessengerServiceProvider.php</file>
</exclude>
</whitelist>
</filter>
Expand Down
24 changes: 15 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://img.shields.io/travis/cmgmyr/laravel-messenger/v2.svg?style=flat-square)](https://travis-ci.org/cmgmyr/laravel-messenger)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/cmgmyr/laravel-messenger/v2.svg?style=flat-square)](https://scrutinizer-ci.com/g/cmgmyr/laravel-messenger/?branch=v2)
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/cmgmyr/laravel-messenger/v2.svg?style=flat-square)](https://scrutinizer-ci.com/g/cmgmyr/laravel-messenger/?branch=v2)
[![Build Status](https://img.shields.io/travis/cmgmyr/laravel-messenger.svg?style=flat-square)](https://travis-ci.org/cmgmyr/laravel-messenger)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/cmgmyr/laravel-messenger.svg?style=flat-square)](https://scrutinizer-ci.com/g/cmgmyr/laravel-messenger/)
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/cmgmyr/laravel-messenger.svg?style=flat-square)](https://scrutinizer-ci.com/g/cmgmyr/laravel-messenger/)
[![Latest Version](https://img.shields.io/github/release/cmgmyr/laravel-messenger.svg?style=flat-square)](https://github.com/cmgmyr/laravel-messenger/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/cmgmyr/messenger.svg?style=flat-square)](https://packagist.org/packages/cmgmyr/messenger)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
Expand Down Expand Up @@ -29,7 +29,11 @@ This package will allow you to add a full user messaging system into your Larave
Installation instructions for Laravel 4 can be [found here](https://github.com/cmgmyr/laravel-messenger/tree/v1).

## Installation (Laravel 5.x)
In composer.json:
```
composer require cmgmyr/messenger
```

Or place manually in composer.json:

```
"require": {
Expand All @@ -51,19 +55,21 @@ Add the service provider to `config/app.php` under `providers`:
],
```

> **Note**: If you are using Laravel 5.5, this step is unnecessary. Laravel Messenger supports [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery).
Publish config:

```
php artisan vendor:publish --provider="Cmgmyr\Messenger\MessengerServiceProvider" --tag="config"
```

Update config file to reference your User Model:

```
config/messenger.php
```

Create a `users` table if you do not have one already. If you need one, simply use [this example](https://github.com/cmgmyr/laravel-messenger/blob/v2/src/Cmgmyr/Messenger/examples/create_users_table.php) as a starting point, then migrate.
Create a `users` table if you do not have one already. If you need one, the default Laravel migration will be satisfactory.

**(Optional)** Define names of database tables in package config file if you don't want to use default ones:

Expand Down Expand Up @@ -96,9 +102,9 @@ class User extends Authenticatable {
```

## Examples
* [Controller](https://github.com/cmgmyr/laravel-messenger/blob/v2/src/Cmgmyr/Messenger/examples/MessagesController.php)
* [Routes](https://github.com/cmgmyr/laravel-messenger/blob/v2/src/Cmgmyr/Messenger/examples/routes.php)
* [Views](https://github.com/cmgmyr/laravel-messenger/tree/v2/src/Cmgmyr/Messenger/examples/views)
* [Controller](https://github.com/cmgmyr/laravel-messenger/tree/master/examples/MessagesController.php)
* [Routes](https://github.com/cmgmyr/laravel-messenger/tree/master/examples/routes.php)
* [Views](https://github.com/cmgmyr/laravel-messenger/tree/master/examples/views)

## Example Projects
* [WIP] [Pusher](https://github.com/cmgmyr/laravel-messenger-pusher-demo)
Expand Down
Loading

0 comments on commit 3da74c4

Please sign in to comment.