Skip to content

Commit dc6f04c

Browse files
committed
2 parents 5600f14 + 41fb010 commit dc6f04c

7 files changed

Lines changed: 16 additions & 20 deletions

File tree

‎app/Http/Controllers/ComputerScienceResourceController.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Events\TagFrequencyChanged;
65
use App\Http\Requests\StoreResourceRequest;
76
use App\Models\ComputerScienceResource;
87
use App\Models\NewsPost;

‎app/Http/Controllers/ResourceEditsController.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Events\TagFrequencyChanged;
65
use App\Http\Requests\StoreResourceEdit;
76
use App\Models\ComputerScienceResource;
87
use App\Models\ResourceEdits;

‎app/Http/Controllers/TagFrequencyController.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public function search(string $type, string $query = '')
1212
return response()->json(['message' => 'Query too long'], 422);
1313
}
1414

15-
if (!in_array($type, ['topics_tags', 'programming_languages_tags', 'general_tags']))
16-
{
15+
if (! in_array($type, ['topics_tags', 'programming_languages_tags', 'general_tags'])) {
1716
return response()->json(['message' => 'Not a valid type'], 422);
1817
}
1918

‎app/Listeners/ModifyTagFrequency.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function __construct()
1818
/**
1919
* Update tag frequencies based on two arrays of tags.
2020
*
21-
* @param array $oldTags Array of old tags (e.g. ['php', 'laravel', ...])
22-
* @param array $newTags Array of new tags (e.g. ['php', 'vue', ...])
21+
* @param array $oldTags Array of old tags (e.g. ['php', 'laravel', ...])
22+
* @param array $newTags Array of new tags (e.g. ['php', 'vue', ...])
2323
*/
2424
public function handle(TagFrequencyChanged $event): void
2525
{

‎app/Models/ComputerScienceResource.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function user(): BelongsTo
6868
protected function imageUrl(): Attribute
6969
{
7070
return Attribute::make(
71-
get: fn() => $this->image_path ? Storage::disk('public')->url($this->image_path) : null,
71+
get: fn () => $this->image_path ? Storage::disk('public')->url($this->image_path) : null,
7272
);
7373
}
7474

@@ -99,8 +99,8 @@ public function edits(): HasMany
9999
protected function platforms(): Attribute
100100
{
101101
return Attribute::make(
102-
get: fn($value) => explode(',', $value),
103-
set: fn($value) => implode(',', $value)
102+
get: fn ($value) => explode(',', $value),
103+
set: fn ($value) => implode(',', $value)
104104
);
105105
}
106106

@@ -110,7 +110,7 @@ protected function platforms(): Attribute
110110
protected function topicTags(): Attribute
111111
{
112112
return Attribute::make(
113-
get: fn() => $this->tagsWithType('topics_tags')->pluck('name')->toArray(),
113+
get: fn () => $this->tagsWithType('topics_tags')->pluck('name')->toArray(),
114114
set: function (array $value) {
115115
$old_value = $this->topic_tags;
116116
$this->syncTagsWithType($value, 'topics_tags');
@@ -127,7 +127,7 @@ protected function topicTags(): Attribute
127127
protected function programmingLanguageTags(): Attribute
128128
{
129129
return Attribute::make(
130-
get: fn() => $this->tagsWithType('programming_languages_tags')->pluck('name')->toArray(),
130+
get: fn () => $this->tagsWithType('programming_languages_tags')->pluck('name')->toArray(),
131131
set: function (array $value) {
132132
$old_value = $this->programming_language_tags;
133133
$this->syncTagsWithType($value, 'programming_languages_tags');
@@ -144,7 +144,7 @@ protected function programmingLanguageTags(): Attribute
144144
protected function generalTags(): Attribute
145145
{
146146
return Attribute::make(
147-
get: fn() => $this->tagsWithType('general_tags')->pluck('name')->toArray(),
147+
get: fn () => $this->tagsWithType('general_tags')->pluck('name')->toArray(),
148148
set: function (array $value) {
149149
$old_value = $this->general_tags;
150150
$this->syncTagsWithType($value, 'general_tags');

‎database/factories/ComputerScienceResourceFactory.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Database\Factories;
44

5-
use App\Events\TagFrequencyChanged;
65
use App\Models\ComputerScienceResource;
76
use App\Models\User;
87
use Illuminate\Database\Eloquent\Factories\Factory;
@@ -60,7 +59,7 @@ public function configure(): Factory
6059
do {
6160
$topicTags = $this->topicTags ?? fake()->randomElements($fakerTags, fake()->numberBetween(3, count($fakerTags)));
6261
$topicTags = array_map([$this, 'sanitizeTag'], $topicTags);
63-
} while (sizeof($topicTags) < 2);
62+
} while (count($topicTags) < 2);
6463

6564
$programmingLanguageTags = $this->programmingLanguageTags ?? fake()->randomElements($fakerTags);
6665
$programmingLanguageTags = array_map([$this, 'sanitizeTag'], $programmingLanguageTags);

‎tests/Feature/TagSearchTest.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public function test_creating_resource_updates_tag_frequency()
7878
$response->assertStatus(200);
7979

8080
// Check that TagFrequency reflects counts
81-
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'python', 'type'=>'topics_tags', 'count' => 1]);
82-
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'python', 'type'=>'programming_languages_tags', 'count' => 1]);
83-
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'algorithms', 'type'=>'topics_tags', 'count' => 1]);
84-
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'beginner', 'type'=>'general_tags', 'count' => 1]);
81+
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'python', 'type' => 'topics_tags', 'count' => 1]);
82+
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'python', 'type' => 'programming_languages_tags', 'count' => 1]);
83+
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'algorithms', 'type' => 'topics_tags', 'count' => 1]);
84+
$this->assertDatabaseHas('tag_frequencies', ['tag' => 'beginner', 'type' => 'general_tags', 'count' => 1]);
8585
}
8686

8787
public function test_dispatching_tag_frequency_change_removes_unused_tags()
@@ -101,15 +101,15 @@ public function test_dispatching_tag_frequency_change_removes_unused_tags()
101101
TagFrequencyChanged::dispatch('general_tags', [
102102
'python',
103103
'java',
104-
'ruby'
104+
'ruby',
105105
], []); // no tags used now
106106

107107
// Step 3: Ensure all tag frequencies are removed
108108
$this->assertDatabaseMissing('tag_frequencies', ['tag' => 'python']);
109109
$this->assertDatabaseMissing('tag_frequencies', ['tag' => 'java']);
110110
$this->assertDatabaseMissing('tag_frequencies', ['tag' => 'ruby']);
111111

112-
$response = $this->getJson(route('tags.search', ['type'=> 'general_tags', 'query' => 'py']));
112+
$response = $this->getJson(route('tags.search', ['type' => 'general_tags', 'query' => 'py']));
113113
$response->assertStatus(200);
114114
$this->assertEmpty($response->json('tags'));
115115
}

0 commit comments

Comments
 (0)