Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 1a2e957

Browse files
committed
rebranding of the package
1 parent 214c04a commit 1a2e957

File tree

10 files changed

+57
-85
lines changed

10 files changed

+57
-85
lines changed

README.md

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
![Laravel Model Mapper](https://user-images.githubusercontent.com/37669560/147101154-e70d8648-ffa3-48c6-b9a8-6a072b7c1f00.png)
1+
# Laravel Loop Functions
2+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/michael-rubel/laravel-loop-functions.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-loop-functions)
3+
[![Total Downloads](https://img.shields.io/packagist/dt/michael-rubel/laravel-loop-functions.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-loop-functions)
4+
[![Code Quality](https://img.shields.io/scrutinizer/quality/g/michael-rubel/laravel-loop-functions.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-loop-functions/?branch=main)
5+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/michael-rubel/laravel-loop-functions.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-loop-functions/?branch=main)
6+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/michael-rubel/laravel-loop-functions/run-tests/main?style=flat-square&label=tests&logo=github)](https://github.com/michael-rubel/laravel-loop-functions/actions)
7+
[![PHPStan](https://img.shields.io/github/workflow/status/michael-rubel/laravel-loop-functions/phpstan/main?style=flat-square&label=larastan&logo=laravel)](https://github.com/michael-rubel/laravel-loop-functions/actions)
28

3-
# Laravel Model-Property Mapper
4-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-model-mapper)
5-
[![Total Downloads](https://img.shields.io/packagist/dt/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-model-mapper)
6-
[![Code Quality](https://img.shields.io/scrutinizer/quality/g/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-model-mapper/?branch=main)
7-
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-model-mapper/?branch=main)
8-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/michael-rubel/laravel-model-mapper/run-tests/main?style=flat-square&label=tests&logo=github)](https://github.com/michael-rubel/laravel-model-mapper/actions)
9-
[![PHPStan](https://img.shields.io/github/workflow/status/michael-rubel/laravel-model-mapper/phpstan/main?style=flat-square&label=larastan&logo=laravel)](https://github.com/michael-rubel/laravel-model-mapper/actions)
10-
11-
This package provides functionality to map your model attributes to local class properties with the same names.
9+
Collection of functions to loop over your data.
1210

1311
The package requires PHP `^8.x` and Laravel `^8.71`.
1412

@@ -19,56 +17,30 @@ The package requires PHP `^8.x` and Laravel `^8.71`.
1917
## Installation
2018
Install the package using composer:
2119
```bash
22-
composer require michael-rubel/laravel-model-mapper
20+
composer require michael-rubel/laravel-loop-functions
2321
```
2422

2523
## Usage
2624
```php
27-
use WithModelMapping;
25+
use WithLoopFunctions;
2826
```
2927

30-
Then in constructor or any other method:
28+
## Available methods
29+
Assign Eloquent model attributes to class properties:
3130
```php
32-
$this->mapModelAttributes($model);
31+
$this->attributesToProperties($model);
3332
```
3433

35-
This is especially handy with Livewire components when you want to map your model data to the view.
36-
37-
For example:
34+
Assign array key values to class properties:
3835
```php
39-
class CompanyProfile extends Component
40-
{
41-
use WithModelMapping;
42-
43-
/**
44-
* Frontend properties.
45-
*
46-
* @var string|null
47-
*/
48-
public ?string $name = null;
49-
public ?string $tax_number = null;
50-
public ?string $address = null;
51-
52-
/**
53-
* @param \App\Models\Company $company
54-
*
55-
* @return void
56-
*/
57-
public function mount(Company $company): void
58-
{
59-
$this->mapModelAttributes($company);
60-
}
61-
}
36+
$this->arrayToProperties($data);
6237
```
6338

64-
## Why?
65-
Why should I use it like this instead of just passing the model to the view? It's because the models are huge objects and you probably shouldn't expose them to the frontend for security and performance reasons. Another thing is primitive view variables are highly customizable through view composers, while it's harder to decorate in the case of using models.
66-
6739
## Logging
6840
As the package doesn't throw an error in case of failed assignment (for example type incompatibility), you may wish to log such an event. The package has failed assignment logging disabled by default, but you can turn it on by publishing the config:
6941

7042
```bash
71-
php artisan vendor:publish --tag="model-mapper-config"
43+
php artisan vendor:publish --tag="loop-functions-config"
7244
```
7345

7446
## Testing

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "michael-rubel/laravel-model-mapper",
3-
"description": "Map your model attributes to class properties with ease.",
2+
"name": "michael-rubel/laravel-loop-functions",
3+
"description": "Collection of functions to loop over your data.",
44
"keywords": [
55
"michael-rubel",
66
"laravel",
7-
"laravel-model-mapper"
7+
"laravel-loop-functions"
88
],
9-
"homepage": "https://github.com/michael-rubel/laravel-model-mapper",
9+
"homepage": "https://github.com/michael-rubel/laravel-loop-functions",
1010
"license": "MIT",
1111
"authors": [
1212
{
@@ -31,12 +31,12 @@
3131
},
3232
"autoload": {
3333
"psr-4": {
34-
"MichaelRubel\\ModelMapper\\": "src"
34+
"MichaelRubel\\LoopFunctions\\": "src"
3535
}
3636
},
3737
"autoload-dev": {
3838
"psr-4": {
39-
"MichaelRubel\\ModelMapper\\Tests\\": "tests"
39+
"MichaelRubel\\LoopFunctions\\Tests\\": "tests"
4040
}
4141
},
4242
"scripts": {
@@ -49,7 +49,7 @@
4949
"extra": {
5050
"laravel": {
5151
"providers": [
52-
"MichaelRubel\\ModelMapper\\ModelMapperServiceProvider"
52+
"MichaelRubel\\LoopFunctions\\LoopFunctionServiceProvider"
5353
]
5454
}
5555
},
File renamed without changes.

src/ModelMapperServiceProvider.php renamed to src/LoopFunctionServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace MichaelRubel\ModelMapper;
5+
namespace MichaelRubel\LoopFunctions;
66

77
use Spatie\LaravelPackageTools\Package;
88
use Spatie\LaravelPackageTools\PackageServiceProvider;
99

10-
class ModelMapperServiceProvider extends PackageServiceProvider
10+
class LoopFunctionServiceProvider extends PackageServiceProvider
1111
{
1212
/**
1313
* Configure the package.
@@ -19,7 +19,7 @@ class ModelMapperServiceProvider extends PackageServiceProvider
1919
public function configurePackage(Package $package): void
2020
{
2121
$package
22-
->name('laravel-model-mapper')
22+
->name('laravel-loop-functions')
2323
->hasConfigFile();
2424
}
2525
}

src/Traits/WithModelMapping.php renamed to src/Traits/WithLoopFunctions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace MichaelRubel\ModelMapper\Traits;
5+
namespace MichaelRubel\LoopFunctions\Traits;
66

77
use Illuminate\Database\Eloquent\Model;
88

9-
trait WithModelMapping
9+
trait WithLoopFunctions
1010
{
1111
/**
1212
* Maps your model attributes to local class properties.
@@ -16,10 +16,10 @@ trait WithModelMapping
1616
*
1717
* @return void
1818
*/
19-
public function mapModelAttributes(?Model $model = null, mixed $rescue = null): void
19+
public function attributesToProperties(?Model $model = null, mixed $rescue = null): void
2020
{
2121
if (! is_null($model)) {
22-
$toIgnore = config('model-mapper.ignore_attributes');
22+
$toIgnore = config('loop-functions.ignore_attributes');
2323

2424
$ignores = is_array($toIgnore)
2525
? $toIgnore
@@ -32,7 +32,7 @@ public function mapModelAttributes(?Model $model = null, mixed $rescue = null):
3232
rescue(
3333
fn () => $this->{$property} = $model->{$property},
3434
$rescue,
35-
config('model-mapper.log') ?? false
35+
config('loop-functions.log') ?? false
3636
);
3737
}
3838
});
@@ -54,7 +54,7 @@ public function arrayToProperties(?array $data, mixed $rescue = null): void
5454
rescue(
5555
fn () => $this->{$key} = $value,
5656
$rescue,
57-
config('model-mapper.log') ?? false
57+
config('loop-functions.log') ?? false
5858
);
5959
}
6060
});

tests/ArrayMappingTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace MichaelRubel\ModelMapper\Tests;
3+
namespace MichaelRubel\LoopFunctions\Tests;
44

5-
use MichaelRubel\ModelMapper\Traits\WithModelMapping;
5+
use MichaelRubel\LoopFunctions\Traits\WithLoopFunctions;
66

77
class ArrayMappingTest extends TestCase
88
{
9-
use WithModelMapping;
9+
use WithLoopFunctions;
1010

1111
public bool $test;
1212
public string $name;

tests/AttributeMappingTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace MichaelRubel\ModelMapper\Tests;
3+
namespace MichaelRubel\LoopFunctions\Tests;
44

55
use Illuminate\Support\Collection;
6-
use MichaelRubel\ModelMapper\Tests\Boilerplate\TestModel;
7-
use MichaelRubel\ModelMapper\Traits\WithModelMapping;
6+
use MichaelRubel\LoopFunctions\Tests\Boilerplate\TestModel;
7+
use MichaelRubel\LoopFunctions\Traits\WithLoopFunctions;
88

99
class AttributeMappingTest extends TestCase
1010
{
11-
use WithModelMapping;
11+
use WithLoopFunctions;
1212

1313
public int $id;
1414
public bool $test;
@@ -30,7 +30,7 @@ public function testMapsAttributesToClassPropertiesCorrectly()
3030
'files' => collect('/img/src/screen.png'),
3131
]);
3232

33-
$this->mapModelAttributes($model);
33+
$this->attributesToProperties($model);
3434

3535
$this->assertTrue($this->test);
3636
$this->assertIsString($this->name);
@@ -49,7 +49,7 @@ public function testMappingIgnoresDifferentTypes()
4949
'default' => fn () => true,
5050
]);
5151

52-
$this->mapModelAttributes($model);
52+
$this->attributesToProperties($model);
5353

5454
$this->assertFalse((new \ReflectionProperty($this, 'name'))->isInitialized($this));
5555
$this->assertFalse((new \ReflectionProperty($this, 'files'))->isInitialized($this));
@@ -66,7 +66,7 @@ public function testMappingWorksWithCollections()
6666
'collection' => new Collection(),
6767
]);
6868

69-
$this->mapModelAttributes($model);
69+
$this->attributesToProperties($model);
7070

7171
$this->assertInstanceOf(Collection::class, $this->collection);
7272
}
@@ -82,7 +82,7 @@ public function testMappingWithCasts()
8282
'intAsString' => 100,
8383
]);
8484

85-
$this->mapModelAttributes($model);
85+
$this->attributesToProperties($model);
8686

8787
$this->assertInstanceOf(Collection::class, $this->collection);
8888
$this->assertIsString($this->intAsString);
@@ -97,7 +97,7 @@ public function testIdAndPasswordIsIgnored()
9797
'test' => true,
9898
]);
9999

100-
$this->mapModelAttributes($model);
100+
$this->attributesToProperties($model);
101101

102102
$this->assertTrue($this->test);
103103
$this->assertFalse((new \ReflectionProperty($this, 'id'))->isInitialized($this));
@@ -107,15 +107,15 @@ public function testIdAndPasswordIsIgnored()
107107
/** @test */
108108
public function testSetsDefaultValueWithWrongConfig()
109109
{
110-
config(['model-mapper.ignore_attributes' => 123]);
110+
config(['loop-functions.ignore_attributes' => 123]);
111111

112112
$model = new TestModel([
113113
'id' => 1,
114114
'password' => 'hash',
115115
'test' => true,
116116
]);
117117

118-
$this->mapModelAttributes($model);
118+
$this->attributesToProperties($model);
119119

120120
$this->assertTrue($this->test);
121121
$this->assertFalse((new \ReflectionProperty($this, 'id'))->isInitialized($this));

tests/Boilerplate/TestModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace MichaelRubel\ModelMapper\Tests\Boilerplate;
3+
namespace MichaelRubel\LoopFunctions\Tests\Boilerplate;
44

55
use Illuminate\Database\Eloquent\Casts\AsCollection;
66
use Illuminate\Database\Eloquent\Model;

tests/LoggingTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace MichaelRubel\ModelMapper\Tests;
3+
namespace MichaelRubel\LoopFunctions\Tests;
44

55
use Illuminate\Support\Facades\Log;
6-
use MichaelRubel\ModelMapper\Tests\Boilerplate\TestModel;
7-
use MichaelRubel\ModelMapper\Traits\WithModelMapping;
6+
use MichaelRubel\LoopFunctions\Tests\Boilerplate\TestModel;
7+
use MichaelRubel\LoopFunctions\Traits\WithLoopFunctions;
88

99
class LoggingTest extends TestCase
1010
{
11-
use WithModelMapping;
11+
use WithLoopFunctions;
1212

1313
public int $number;
1414

@@ -25,20 +25,20 @@ public function testMapperCanLog()
2525
'number' => false,
2626
]);
2727

28-
$this->mapModelAttributes($model);
28+
$this->attributesToProperties($model);
2929
}
3030

3131
/** @test */
3232
public function testMapperDoesntLogIfDisabled()
3333
{
34-
config(['model-mapper.log' => false]);
34+
config(['loop-functions.log' => false]);
3535

3636
Log::shouldReceive('error')->never();
3737

3838
$model = new TestModel([
3939
'number' => false,
4040
]);
4141

42-
$this->mapModelAttributes($model);
42+
$this->attributesToProperties($model);
4343
}
4444
}

tests/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace MichaelRubel\ModelMapper\Tests;
3+
namespace MichaelRubel\LoopFunctions\Tests;
44

5-
use MichaelRubel\ModelMapper\ModelMapperServiceProvider;
5+
use MichaelRubel\LoopFunctions\LoopFunctionServiceProvider;
66
use Orchestra\Testbench\TestCase as Orchestra;
77

88
class TestCase extends Orchestra
@@ -15,7 +15,7 @@ public function setUp(): void
1515
protected function getPackageProviders($app): array
1616
{
1717
return [
18-
ModelMapperServiceProvider::class,
18+
LoopFunctionServiceProvider::class,
1919
];
2020
}
2121

0 commit comments

Comments
 (0)