• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Freegle / Iznik / 11933

10 May 2026 06:13AM UTC coverage: 72.889% (+0.05%) from 72.843%
11933

push

circleci

web-flow
Merge pull request #405 from Freegle/feat/batch-migrate-non-email-jobs

feat(batch): migrate non-email cron scripts to Laravel artisan commands

13854 of 20887 branches covered (66.33%)

Branch coverage included in aggregate %.

789 of 1004 new or added lines in 21 files covered. (78.59%)

36 existing lines in 3 files now uncovered.

102807 of 139167 relevant lines covered (73.87%)

22.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/iznik-batch/app/Models/Location.php
1
<?php
2

3
namespace App\Models;
4

5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7

8
class Location extends Model
9
{
10
    protected $table = 'locations';
11
    protected $guarded = ['id'];
12
    public $timestamps = FALSE;
13

14
    protected $casts = [
15
        'lat' => 'decimal:6',
16
        'lng' => 'decimal:6',
17
        'osm_place' => 'boolean',
18
        'osm_amenity' => 'boolean',
19
        'osm_shop' => 'boolean',
20
    ];
21

NEW
22
    public static function closestPostcode(float $lat, float $lng): ?object
×
23
    {
NEW
24
        $srid = config('freegle.srid', 3857);
×
NEW
25
        $scan = 0.00001953125;
×
26

27
        do {
NEW
28
            $swlat = $lat - $scan;
×
NEW
29
            $nelat = $lat + $scan;
×
NEW
30
            $swlng = $lng - $scan;
×
NEW
31
            $nelng = $lng + $scan;
×
32

NEW
33
            $poly = "POLYGON(($swlng $swlat, $swlng $nelat, $nelng $nelat, $nelng $swlat, $swlng $swlat))";
×
34

NEW
35
            $locs = DB::select(
×
NEW
36
                "SELECT locations.id, locations.name, locations.lat, locations.lng
×
37
                 FROM locations_spatial
38
                 INNER JOIN locations ON locations.id = locations_spatial.locationid
39
                 WHERE MBRContains(ST_Envelope(ST_GeomFromText(?, ?)), locations_spatial.geometry)
40
                   AND locations.type = 'Postcode'
41
                   AND LOCATE(' ', locations.name) > 0
42
                 ORDER BY ST_distance(locations_spatial.geometry, ST_GeomFromText(?, ?)) ASC
NEW
43
                 LIMIT 1",
×
NEW
44
                [$poly, $srid, "POINT($lng $lat)", $srid]
×
NEW
45
            );
×
46

NEW
47
            if (count($locs) === 1) {
×
NEW
48
                return $locs[0];
×
49
            }
50

NEW
51
            $scan *= 2;
×
NEW
52
        } while ($scan <= 0.2);
×
53

NEW
54
        return null;
×
55
    }
56

NEW
57
    public static function findByName(string $name): ?int
×
58
    {
NEW
59
        return static::getByName($name)?->id;
×
60
    }
61

62
    public static function getByName(string $name): ?object
3✔
63
    {
64
        $canon = strtolower(preg_replace("/[^A-Za-z0-9]/", '', $name));
3✔
65
        return DB::table('locations')->where('canon', 'LIKE', $canon)->first();
3✔
66
    }
67

68
    public static function groupsNear(float $lat, float $lng, int $radiusMiles = 50, int $limit = 10): array
9✔
69
    {
70
        $rows = DB::select(
9✔
71
            "SELECT id
9✔
72
             FROM `groups`
73
             WHERE publish = 1 AND listable = 1
74
               AND haversine(lat, lng, ?, ?) < ?
75
             ORDER BY haversine(lat, lng, ?, ?) ASC
76
             LIMIT ?",
9✔
77
            [$lat, $lng, $radiusMiles, $lat, $lng, $limit]
9✔
78
        );
9✔
79

80
        return array_column($rows, 'id');
9✔
81
    }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc