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

Upgrade PHP #642

Closed
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
php-version: '8.1'
extensions: mbstring, dom, fileinfo, mysql
# coverage: xdebug #optional
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/public/local-uploads/*
/public/sitemap.xml
/storage/*.key
/storage/pint.cache
/storage/rector/cache
/vendor
.env
.env.backup
Expand All @@ -15,3 +17,4 @@ yarn-error.log
.vscode
.idea
.eslintignore
.DS_Store
9 changes: 1 addition & 8 deletions app/Actions/Locations/ReverseGeocodeLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class ReverseGeocodeLocationAction
/** @var Client */
private $client;

/**
* @param Client $client
*/
public function __construct (Client $client)
{
$this->client = $client;
Expand All @@ -21,20 +18,16 @@ public function __construct (Client $client)
/**
* Using the GPS coordinates from the image, return the Reverse Geocode result from OpenStreetMap
*
* eg country => Ireland, city => Cork, country_code => ie
*
* @param $latitude
* @param $longitude
*
* @return array
* @throws GuzzleException
*/
public function run ($latitude, $longitude): array
{
$apiKey = config('services.location.secret');

$url = "https://eu1.locationiq.com/v1/reverse.php?format=json" .
"&key=" . $apiKey . "&lat=" . $latitude . "&lon=" . $longitude . "&zoom=20";
$url = 'https://eu1.locationiq.com/v1/reverse.php?format=json&key=' . $apiKey . "&lat=" . $latitude . "&lon=" . $longitude . "&zoom=20";

return json_decode(
$this->client->get($url)->getBody(),
Expand Down
7 changes: 0 additions & 7 deletions app/Actions/Locations/UpdateLeaderboardsForLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class UpdateLeaderboardsForLocationAction
/** @var UpdateLeaderboardsXpAction */
protected $updateXpAction;

/**
* @param UpdateLeaderboardsXpAction $updateXpAction
*/
public function __construct (UpdateLeaderboardsXpAction $updateXpAction)
{
$this->updateXpAction = $updateXpAction;
Expand All @@ -23,10 +20,6 @@ public function __construct (UpdateLeaderboardsXpAction $updateXpAction)
* Update the Leaderboards for each Location
*
* All time + time-stamped
*
* @param Photo $photo
* @param int $userId
* @param int $incrXp
*/
public function run (
Photo $photo,
Expand Down
4 changes: 0 additions & 4 deletions app/Actions/Locations/UpdateLeaderboardsXpAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

class UpdateLeaderboardsXpAction
{
/**
* @param int $userId
* @param int $incrXp
*/
public function run (
int $userId,
int $incrXp
Expand Down
8 changes: 3 additions & 5 deletions app/Actions/Locations/UpdateTotalPhotosForLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class UpdateTotalPhotosForLocationAction
{
public const KEY = 'total_photos';
final public const KEY = 'total_photos';

/**
* Increments or decrements total_photos
Expand Down Expand Up @@ -37,10 +37,8 @@ public function run(string $countryId, string $stateId, string $cityId, int $inc
protected function updateValue($hashName, $value)
{
// Separate if conditions to skip redis check when $value is positive
if ($value < 0) {
if (Redis::hget($hashName, self::KEY) + $value < 0) {
return;
}
if ($value < 0 && Redis::hget($hashName, self::KEY) + $value < 0) {
return;
}

Redis::hincrby($hashName, self::KEY, $value);
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Photos/AddCustomTagsToPhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AddCustomTagsToPhotoAction
*/
public function run (Photo $photo, array $tags): int
{
if (empty($tags)) {
if ($tags === []) {
return 0;
}

Expand Down
7 changes: 1 addition & 6 deletions app/Actions/Photos/AddTagsToPhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class AddTagsToPhotoAction
/**
* Adds tags to the photo.
*
* @param Photo $photo
* @param $tags
*
* @return array number of added tags, total litter and brands
*/
public function run (Photo $photo, $tags): array
Expand All @@ -36,14 +34,11 @@ public function run (Photo $photo, $tags): array

$all = $litter + $brands;

return compact('litter', 'brands', 'all');
return ['litter' => $litter, 'brands' => $brands, 'all' => $all];
}

/**
* Creates new rows on respective category tables
*
* @param Photo $photo
* @param string $category
*/
protected function createCategory (Photo $photo, string $category): void
{
Expand Down
7 changes: 1 addition & 6 deletions app/Actions/Photos/DeletePhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class DeletePhotoAction
* we'll just assume the photo has already been deleted
* or has been partially uploaded, in which case there's nothing to delete.
* That's why we're not throwing an exception here
*
* @param Photo $photo
*/
public function run (Photo $photo)
{
Expand All @@ -30,14 +28,11 @@ public function run (Photo $photo)

/**
* Delete a photo from a specified disk
*
* @param string $filename
* @param string $disk
*/
protected function deletePhoto (string $filename, string $disk) :void
{
$path = str_replace(
rtrim(Storage::disk($disk)->url('/'), '/'),
rtrim((string) Storage::disk($disk)->url('/'), '/'),
'',
$filename
);
Expand Down
6 changes: 2 additions & 4 deletions app/Actions/Photos/DeleteTagsFromPhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class DeleteTagsFromPhotoAction
*
* Returns the total number of tags that were deleted, separated from brands
*
* @param Photo $photo
*
* @return array
*/
public function run(Photo $photo): array
{
Expand All @@ -26,14 +24,14 @@ public function run(Photo $photo): array

$all = $litter + $brands + $custom;

return compact('litter', 'brands', 'custom', 'all');
return ['litter' => $litter, 'brands' => $brands, 'custom' => $custom, 'all' => $all];
}

private function deleteLitter(Photo $photo): int
{
$categories = collect($photo->categories())
->filter(function ($category) use ($photo) {
return $category !== 'brands' && !!$photo->$category;
return $category !== 'brands' && (bool) $photo->$category;
});

$total = $categories->sum(function ($category) use ($photo) {
Expand Down
9 changes: 2 additions & 7 deletions app/Actions/Photos/MakeImageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ class MakeImageAction
/**
* Create an instance of Intervention Image using an UploadedFile
*
* @param UploadedFile $file
* @param bool $resize
*
* @return array
*/
public function run(UploadedFile $file, bool $resize = false): array
{
Expand All @@ -35,8 +32,6 @@ public function run(UploadedFile $file, bool $resize = false): array
}

/**
* @param UploadedFile $file
* @return array
* @throws Exception
*/
protected function getImageAndExifData(UploadedFile $file): array
Expand All @@ -50,7 +45,7 @@ protected function getImageAndExifData(UploadedFile $file): array
$image = Image::make($file)->orientate();
$exif = $image->exif();

return compact('image', 'exif');
return ['image' => $image, 'exif' => $exif];
}

// Generating a random filename, and not using the image's
Expand Down Expand Up @@ -84,6 +79,6 @@ protected function getImageAndExifData(UploadedFile $file): array
unlink($tmpFilepath);
unlink($convertedFilepath);

return compact('image', 'exif');
return ['image' => $image, 'exif' => $exif];
}
}
8 changes: 0 additions & 8 deletions app/Actions/Photos/UploadPhotoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ class UploadPhotoAction
/**
* Upload photo to a specific disk
*
* @param Image $photo
* @param Carbon $datetime
* @param string $filename
* @param string $disk
*
* @return string
*/
public function run (Image $photo, Carbon $datetime, string $filename, string $disk = 's3'): string
{
Expand All @@ -34,10 +29,7 @@ public function run (Image $photo, Carbon $datetime, string $filename, string $d
*
* eg: /yyyy/mm/dd/filepath.png
*
* @param Carbon $datetime
* @param string $filename
*
* @return string
*/
protected function extractPath (Carbon $datetime, string $filename): string
{
Expand Down
5 changes: 0 additions & 5 deletions app/Actions/Teams/CreateTeamAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public function run(User $user, array $data): Team
return $team;
}

/**
* @param User $user
* @param Team $team
* @return void
*/
protected function addUserAsTeamMember(User $user, Team $team): void
{
$user->teams()->attach($team);
Expand Down
5 changes: 0 additions & 5 deletions app/Actions/Teams/JoinTeamAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public function run(User $user, Team $team)
$team->save();
}

/**
* @param User $user
* @param Team $team
* @return void
*/
protected function setAsActiveTeamIfNull(User $user, Team $team): void
{
if (is_null($user->active_team)) {
Expand Down
6 changes: 0 additions & 6 deletions app/Actions/Teams/LeaveTeamAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public function run(User $user, Team $team)
/**
* If the user is the leader of the team they're leaving
* assign a new team member as leader
*
* @param User $user
* @param Team $team
*/
protected function assignTeamLeader(User $user, Team $team): void
{
Expand All @@ -49,9 +46,6 @@ protected function assignTeamLeader(User $user, Team $team): void
* If the user is leaving their active team
* assign a new active team to them
* if they are part of another team
*
* @param User $user
* @param Team $team
*/
protected function assignActiveTeam(User $user, Team $team): void
{
Expand Down
1 change: 0 additions & 1 deletion app/Broadcasting/UsersChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function __construct()
/**
* Authenticate the user's access to the channel.
*
* @param \App\Models\User\User $user
* @return array|bool
*/
public function join(User $user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,5 @@ public function handle()
}

echo "Completed.";

return;
}
}
10 changes: 6 additions & 4 deletions app/Console/Commands/Clusters/GenerateClusters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Console\Commands\Clusters;

use Illuminate\Support\Facades\Log;
use GeoHash;
use App\Models\Photo;
use App\Models\Cluster;

Expand Down Expand Up @@ -30,7 +32,7 @@ class GenerateClusters extends Command
*/
public function handle()
{
\Log::info('--- Clustering began ---');
Log::info('--- Clustering began ---');

$start = microtime(true);

Expand All @@ -44,7 +46,7 @@ public function handle()
$this->newLine();
$this->info("Total Time: " . ($finish - $start) . "\n");

\Log::info('--- Clustering finished ---');
Log::info('--- Clustering finished ---');
}

/**
Expand Down Expand Up @@ -138,7 +140,7 @@ protected function generateClusters (int $year = null): void
'lon' => $cluster->geometry->coordinates[0],
'point_count' => $cluster->properties->point_count,
'point_count_abbreviated' => $cluster->properties->point_count_abbreviated,
'geohash' => \GeoHash::encode($cluster->geometry->coordinates[1], $cluster->geometry->coordinates[0]),
'geohash' => GeoHash::encode($cluster->geometry->coordinates[1], $cluster->geometry->coordinates[0]),
'zoom' => $zoomLevel,
'year' => $year
];
Expand Down Expand Up @@ -179,7 +181,7 @@ private function getYearsWithNewPhotos(): array
}
}

return empty($yearsWithData)
return $yearsWithData === []
? []
: array_merge([null], $yearsWithData);
}
Expand Down
7 changes: 3 additions & 4 deletions app/Console/Commands/Clusters/GenerateTeamClusters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands\Clusters;

use GeoHash;
use App\Models\Photo;
use App\Models\TeamCluster;
use App\Models\Teams\Team;
Expand All @@ -25,6 +26,7 @@ class GenerateTeamClusters extends Command
protected $description = 'Generate all clusters for teams photos';

private $clustersDir = 'team-clusters.json';

private $featuresDir = 'team-features.json';

/**
Expand Down Expand Up @@ -126,7 +128,7 @@ protected function generateClusters(Team $team): void
'lon' => $cluster->geometry->coordinates[0],
'point_count' => $cluster->properties->point_count,
'point_count_abbreviated' => $cluster->properties->point_count_abbreviated,
'geohash' => \GeoHash::encode($cluster->geometry->coordinates[1], $cluster->geometry->coordinates[0]),
'geohash' => GeoHash::encode($cluster->geometry->coordinates[1], $cluster->geometry->coordinates[0]),
'created_at' => $time,
'updated_at' => $time,
];
Expand All @@ -144,9 +146,6 @@ protected function generateClusters(Team $team): void
$this->info("\nClusters finished...");
}

/**
* @param Team $team
*/
protected function deleteClusters(Team $team)
{
$this->info("Deleting clusters...");
Expand Down
Loading