Skip to content

Commit 8e2cc37

Browse files
committed
Version Patch
- Update dependency to support Laravel 8 - Add [CHANGELOG.md](CHANGELOG.md) - Add composer scripts for testing and code fixing - Add ignore of .php_cs.cache - Apply PSR style formatting
1 parent 5625212 commit 8e2cc37

13 files changed

+388
-337
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
composer.lock
1010
/vendor
1111
.phpintel/*
12-
.phpunit.result.cache
12+
.phpunit.result.cache
13+
.php_cs.cache

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to `rtconner/laravel-likeable` will be documented in this file
4+
5+
## 2020-09-26
6+
7+
- Update dependency to support Laravel 8
8+
- Add [CHANGELOG.md](CHANGELOG.md)
9+
- Add composer scripts for testing and code fixing
10+
- Add ignore of .php_cs.cache
11+
- Apply PSR style formatting

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Important Note: As of version 1.2 I renamed `Conner\Likeable\LikeableTrait` to `
99

1010
Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" feature.
1111

12-
[Laravel 5/6/7 Documentation](https://github.com/rtconner/laravel-likeable/tree/laravel-7)
12+
[Laravel 5/6/7/8 Documentation](https://github.com/rtconner/laravel-likeable/tree/laravel-7)
1313
[Laravel 4 Documentation](https://github.com/rtconner/laravel-likeable/tree/laravel-4)
1414

15-
#### Composer Install (for Laravel 5)
15+
#### Composer Install
1616

17-
composer require rtconner/laravel-likeable "~3.0"
17+
composer require rtconner/laravel-likeable
1818

1919
#### Then run the migrations
2020

@@ -26,7 +26,7 @@ php artisan migrate
2626

2727
```php
2828
class Article extends \Illuminate\Database\Eloquent\Model {
29-
use \Conner\Likeable\LikeableTrait;
29+
use \Conner\Likeable\Likeable;
3030
}
3131
```
3232

@@ -43,7 +43,7 @@ $article->unlike(0); // remove likes from the count -- does not check for user
4343

4444
$article->likeCount; // get count of likes
4545

46-
$article->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes
46+
$article->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes
4747

4848
$article->liked(); // check if currently logged in user liked the article
4949
$article->liked($myUserId);

composer.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
],
1313
"require": {
1414
"php": ">=5.6.0",
15-
"illuminate/database": ">=5.0|^6.0|^7.0",
16-
"illuminate/support": ">=5.0|^6.0|^7.0"
15+
"illuminate/database": ">=5.0|^6.0|^7.0|^8.0",
16+
"illuminate/support": ">=5.0|^6.0|^7.0|^8.0"
1717
},
1818
"require-dev": {
19-
"orchestra/testbench": "5.*",
20-
"phpunit/phpunit": "8.*",
19+
"orchestra/testbench": "5.*|6.*",
20+
"phpunit/phpunit": "8.*|9.*",
2121
"mockery/mockery": "1.*"
2222
},
2323
"autoload": {
@@ -30,6 +30,17 @@
3030
"Conner\\Tests\\Likeable\\": "tests/"
3131
}
3232
},
33+
"scripts": {
34+
"test": "vendor/bin/phpunit --color=always",
35+
"check": [
36+
"php-cs-fixer fix --ansi --dry-run --diff .",
37+
"phpcs --report-width=200 --report-summary --report-full src/ tests/ --standard=PSR2 -n",
38+
"phpmd src/,tests/ text ./phpmd.xml.dist"
39+
],
40+
"fix": [
41+
"php-cs-fixer fix --ansi ."
42+
]
43+
},
3344
"extra": {
3445
"laravel": {
3546
"providers": [

migrations/2016_02_07_000000_create_likeable_tables.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@
55

66
class CreateLikeableTables extends Migration
77
{
8-
public function up()
9-
{
10-
Schema::create('likeable_likes', function(Blueprint $table) {
11-
$table->bigIncrements('id');
12-
$table->string('likeable_id', 36);
13-
$table->string('likeable_type', 255);
14-
$table->string('user_id', 36)->index();
15-
$table->timestamps();
16-
$table->unique(['likeable_id', 'likeable_type', 'user_id'], 'likeable_likes_unique');
17-
});
18-
19-
Schema::create('likeable_like_counters', function(Blueprint $table) {
20-
$table->bigIncrements('id');
21-
$table->string('likeable_id', 36);
22-
$table->string('likeable_type', 255);
23-
$table->unsignedBigInteger('count')->default(0);
24-
$table->unique(['likeable_id', 'likeable_type'], 'likeable_counts');
25-
});
26-
27-
}
8+
public function up()
9+
{
10+
Schema::create('likeable_likes', function (Blueprint $table) {
11+
$table->bigIncrements('id');
12+
$table->string('likeable_id', 36);
13+
$table->string('likeable_type', 255);
14+
$table->string('user_id', 36)->index();
15+
$table->timestamps();
16+
$table->unique(['likeable_id', 'likeable_type', 'user_id'], 'likeable_likes_unique');
17+
});
18+
19+
Schema::create('likeable_like_counters', function (Blueprint $table) {
20+
$table->bigIncrements('id');
21+
$table->string('likeable_id', 36);
22+
$table->string('likeable_type', 255);
23+
$table->unsignedBigInteger('count')->default(0);
24+
$table->unique(['likeable_id', 'likeable_type'], 'likeable_counts');
25+
});
26+
}
2827

29-
public function down()
30-
{
31-
Schema::drop('likeable_likes');
32-
Schema::drop('likeable_like_counters');
33-
}
28+
public function down()
29+
{
30+
Schema::drop('likeable_likes');
31+
Schema::drop('likeable_like_counters');
32+
}
3433
}

phpmd.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ruleset
3+
name="ProxyManager rules"
4+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
8+
>
9+
<rule ref="rulesets/codesize.xml"/>
10+
<rule ref="rulesets/unusedcode.xml"/>
11+
<rule ref="rulesets/design.xml">
12+
<!-- eval is needed to generate runtime classes -->
13+
<exclude name="EvalExpression"/>
14+
</rule>
15+
<rule ref="rulesets/naming.xml">
16+
<exclude name="LongVariable"/>
17+
</rule>
18+
<rule ref="rulesets/naming.xml/LongVariable">
19+
<properties>
20+
<property name="minimum">40</property>
21+
</properties>
22+
</rule>
23+
</ruleset>

src/Like.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
*/
1414
class Like extends Eloquent
1515
{
16-
protected $table = 'likeable_likes';
17-
public $timestamps = true;
18-
protected $fillable = ['likeable_id', 'likeable_type', 'user_id'];
16+
protected $table = 'likeable_likes';
17+
public $timestamps = true;
18+
protected $fillable = ['likeable_id', 'likeable_type', 'user_id'];
1919

2020
/**
2121
* @access private
2222
*/
23-
public function likeable()
24-
{
25-
return $this->morphTo();
26-
}
27-
}
23+
public function likeable()
24+
{
25+
return $this->morphTo();
26+
}
27+
}

src/LikeCounter.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,38 @@
1010
*/
1111
class LikeCounter extends Eloquent
1212
{
13-
protected $table = 'likeable_like_counters';
14-
public $timestamps = false;
15-
protected $fillable = ['likeable_id', 'likeable_type', 'count'];
13+
protected $table = 'likeable_like_counters';
14+
public $timestamps = false;
15+
protected $fillable = ['likeable_id', 'likeable_type', 'count'];
1616

1717
/**
1818
* @access private
1919
*/
20-
public function likeable()
21-
{
22-
return $this->morphTo();
23-
}
20+
public function likeable()
21+
{
22+
return $this->morphTo();
23+
}
2424

2525
/**
2626
* Delete all counts of the given model, and recount them and insert new counts
2727
*
2828
* @param $modelClass
2929
*/
30-
public static function rebuild($modelClass)
31-
{
32-
if(empty($modelClass)) {
30+
public static function rebuild($modelClass)
31+
{
32+
if (empty($modelClass)) {
3333
throw new \Exception('$modelClass cannot be empty/null. Maybe set the $morphClass variable on your model.');
34-
}
35-
36-
$builder = Like::query()
37-
->select(\DB::raw('count(*) as count, likeable_type, likeable_id'))
38-
->where('likeable_type', $modelClass)
39-
->groupBy('likeable_id');
40-
41-
$results = $builder->get();
42-
43-
$inserts = $results->toArray();
44-
45-
\DB::table((new static)->table)->insert($inserts);
46-
}
47-
48-
}
34+
}
35+
36+
$builder = Like::query()
37+
->select(\DB::raw('count(*) as count, likeable_type, likeable_id'))
38+
->where('likeable_type', $modelClass)
39+
->groupBy('likeable_id');
40+
41+
$results = $builder->get();
42+
43+
$inserts = $results->toArray();
44+
45+
\DB::table((new static)->table)->insert($inserts);
46+
}
47+
}

0 commit comments

Comments
 (0)