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

Add space after function keyword for PSR2 #214

Merged
merged 4 commits into from
Oct 5, 2024
Merged
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 architecture/developer-guide.md
Original file line number Diff line number Diff line change
@@ -407,7 +407,7 @@ ProductCategory
When dynamically extending other plugin's models, you should prefix the field with at least the plugin name. This helps to avoid potential future conflicts if that plugin is updated to add new relationships that could conflict with your dynamic relationships.

```php
User::extend(function($model) {
User::extend(function ($model) {
$model->hasOne['forum_member'] = ['Winter\Forum\Models\Member'];
});
```
4 changes: 2 additions & 2 deletions architecture/introduction.md
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ See below for a sample of what is possible with dynamic class extension:

```php
// Dynamically extend a model that belongs to a third party plugin
Post::extend(function($model) {
Post::extend(function ($model) {
// Bind to an event that's only fired locally
$model->bindEvent('model.afterSave', function () use ($model) {
if (!$model->isValid()) {
@@ -151,7 +151,7 @@ Post::extend(function($model) {
$model->addDynamicProperty('tagsCache', null);

// Add a new method to the class
$model->addDynamicMethod('getTagsAttribute', function() use ($model) {
$model->addDynamicMethod('getTagsAttribute', function () use ($model) {
if ($model->tagsCache) {
return $model->tagsCache;
} else {
2 changes: 1 addition & 1 deletion backend/forms.md
Original file line number Diff line number Diff line change
@@ -1736,7 +1736,7 @@ class Categories extends \Backend\Classes\Controller
Using the `extendFormFields` method you can add extra fields to any form rendered by this controller. Since this has the potential to affect all forms used by this controller, it is a good idea to check the **$model** is of the correct type. Here is an example:

```php
Categories::extendFormFields(function($form, $model, $context)
Categories::extendFormFields(function ($form, $model, $context)
{
if (!$model instanceof MyModel) {
return;
8 changes: 4 additions & 4 deletions backend/lists.md
Original file line number Diff line number Diff line change
@@ -711,7 +711,7 @@ published_at:
To use default value for Date and Date Range

```php
myController::extendListFilterScopes(function($filter)
myController::extendListFilterScopes(function ($filter)
{
$filter->addScopes([
'Date Test' => [
@@ -887,7 +887,7 @@ class Categories extends \Backend\Classes\Controller
Using the `extendListColumns` method you can add extra columns to any list rendered by this controller. It is a good idea to check the **$model** is of the correct type. Here is an example:

```php
Categories::extendListColumns(function($list, $model)
Categories::extendListColumns(function ($list, $model)
{
if (!$model instanceof MyModel) {
return;
@@ -960,7 +960,7 @@ public function listInjectRowClass($record, $value)
You can extend the filter scopes of another controller from outside by calling the `extendListFilterScopes` static method on the controller class. This method can take the argument **$filter** which will represent the Filter widget object. Take this controller for example:

```php
Categories::extendListFilterScopes(function($filter) {
Categories::extendListFilterScopes(function ($filter) {
// Add custom CSS classes to the Filter widget itself
$filter->cssClasses = array_merge($filter->cssClasses, ['my', 'array', 'of', 'classes']);

@@ -1060,7 +1060,7 @@ public function registerListColumnTypes()
'uppercase' => [$this, 'evalUppercaseListColumn'],

// Using an inline closure
'loveit' => function($value) { return 'I love '. $value; }
'loveit' => function ($value) { return 'I love '. $value; }
];
}

4 changes: 2 additions & 2 deletions cms/mediamanager.md
Original file line number Diff line number Diff line change
@@ -264,7 +264,7 @@ Event | Description | Parameters
**To hook into these events, either extend the `Backend\Widgets\MediaManager` class directly:**

```php
Backend\Widgets\MediaManager::extend(function($widget) {
Backend\Widgets\MediaManager::extend(function ($widget) {
$widget->bindEvent('file.rename', function ($originalPath, $newPath) {
// Update custom references to path here
});
@@ -274,7 +274,7 @@ Backend\Widgets\MediaManager::extend(function($widget) {
**Or listen globally via the `Event` facade (each event is prefixed with `media.` and will be passed the instantiated `Backend\Widgets\MediaManager` object as the first parameter):**

```php
Event::listen('media.file.rename', function($widget, $originalPath, $newPath) {
Event::listen('media.file.rename', function ($widget, $originalPath, $newPath) {
// Update custom references to path here
});
```
2 changes: 1 addition & 1 deletion console/introduction.md
Original file line number Diff line number Diff line change
@@ -483,7 +483,7 @@ If you need to register commands from within a [service provider](../services/ap
```php
public function boot()
{
$this->app->singleton('myauthor.mycommand', function() {
$this->app->singleton('myauthor.mycommand', function () {
return new \MyAuthor\MyCommand\Console\MyCommand;
});

2 changes: 1 addition & 1 deletion database/basics.md
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ Db::commit();
If you would like to receive each SQL query executed by your application, you may use the `listen` method. This method is useful for logging queries or debugging.

```php
Db::listen(function($sql, $bindings, $time) {
Db::listen(function ($sql, $bindings, $time) {
//
});
```
4 changes: 2 additions & 2 deletions database/behaviors.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ You can also dynamically implement this behavior on third party models outside o
/**
* Extend the Winter.User user model to implement the encryptable behavior.
*/
Winter\User\Models\User::extend(function($model) {
Winter\User\Models\User::extend(function ($model) {
// Implement the sortable behavior dynamically
$model->implement[] = 'Winter.Storm.Database.Behaviors.Encryptable';
$model->addDynamicProperty('encryptable', ['encrypted_metadata']);
@@ -54,7 +54,7 @@ You can also dynamically implement this behavior on third party models outside o
/**
* Extend the Winter.User user model to implement the sortable behavior.
*/
Winter\User\Models\User::extend(function($model) {
Winter\User\Models\User::extend(function ($model) {
// Implement the sortable behavior dynamically
$model->implement[] = 'Winter.Storm.Database.Behaviors.Sortable';
});
2 changes: 1 addition & 1 deletion database/collection.md
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@ $feed = new Winter\Storm\Database\DataFeed;
$feed->add('user', new User);
$feed->add('post', Post::where('category_id', 7));

$feed->add('comment', function() {
$feed->add('comment', function () {
$comment = new Comment;
return $comment->where('approved', true);
});
12 changes: 6 additions & 6 deletions database/model.md
Original file line number Diff line number Diff line change
@@ -662,7 +662,7 @@ You can externally bind to [local events](../events/introduction) for a single i

```php
$flight = new Flight;
$flight->bindEvent('model.beforeCreate', function() use ($model) {
$flight->bindEvent('model.beforeCreate', function () use ($model) {
$model->slug = Str::slug($model->name);
})
```
@@ -674,16 +674,16 @@ Since models are [equipped to use behaviors](../services/behaviors), they can be
Inside the closure you can add relations to the model. Here we extend the `Backend\Models\User` model to include a profile (has one) relationship referencing the `Acme\Demo\Models\Profile` model.

```php
\Backend\Models\User::extend(function($model) {
\Backend\Models\User::extend(function ($model) {
$model->hasOne['profile'] = ['Acme\Demo\Models\Profile', 'key' => 'user_id'];
});
```

This approach can also be used to bind to [local events](#events), the following code listens for the `model.beforeSave` event.

```php
\Backend\Models\User::extend(function($model) {
$model->bindEvent('model.beforeSave', function() use ($model) {
\Backend\Models\User::extend(function ($model) {
$model->bindEvent('model.beforeSave', function () use ($model) {
// ...
});
});
@@ -696,7 +696,7 @@ This approach can also be used to bind to [local events](#events), the following
Additionally, a few methods exist to extend protected model properties.

```php
\Backend\Models\User::extend(function($model) {
\Backend\Models\User::extend(function ($model) {
// add cast attributes
$model->addCasts([
'some_extended_field' => 'int',
@@ -741,7 +741,7 @@ It is strongly suggested to use the above methods to add relations when extendin
Example usage:

```php
\Backend\Models\User::extend(function($model) {
\Backend\Models\User::extend(function ($model) {
$model->addHasOne('profile', ['Acme\Demo\Models\Profile', 'key' => 'user_id']);
});
```
4 changes: 2 additions & 2 deletions database/query.md
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ foreach ($roles as $name => $title) {
If you need to work with thousands of database records, consider using the `chunk` method. This method retrieves a small "chunk" of the results at a time, and feeds each chunk into a `Closure` for processing. This method is very useful for writing [console commands](../console/introduction#building-a-command) that process thousands of records. For example, let's work with the entire `users` table in chunks of 100 records at a time:

```php
Db::table('users')->chunk(100, function($users) {
Db::table('users')->chunk(100, function ($users) {
foreach ($users as $user) {
//
}
@@ -77,7 +77,7 @@ Db::table('users')->chunk(100, function($users) {
You may stop further chunks from being processed by returning `false` from the `Closure`:

```php
Db::table('users')->chunk(100, function($users) {
Db::table('users')->chunk(100, function ($users) {
// Process the records...

return false;
2 changes: 1 addition & 1 deletion database/relations.md
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ Many-to-many relations are slightly more complicated than `hasOne` and `hasMany`
Below is an example that shows the [database table structure](../plugin/updates#migration-and-seed-files) used to create the join table.

```php
Schema::create('role_user', function($table)
Schema::create('role_user', function ($table)
{
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
2 changes: 1 addition & 1 deletion database/structure.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class CreatePostsTable extends Migration
{
public function up()
{
Schema::create('winter_blog_posts', function($table)
Schema::create('winter_blog_posts', function ($table)
{
$table->engine = 'InnoDB';
$table->increments('id');
8 changes: 4 additions & 4 deletions plugin/extending.md
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ class Plugin extends PluginBase
public function boot()
{
// Extend all backend form usage
Event::listen('backend.form.extendFields', function($widget) {
Event::listen('backend.form.extendFields', function ($widget) {
// Only apply this listener when the Users controller is being used
if (!$widget->getController() instanceof \Winter\User\Controllers\Users) {
return;
@@ -262,7 +262,7 @@ slug = "{{ :slug }}"
==
function onInit()
{
$this['topic']->bindEvent('topic.post', function($post, $postUrl) {
$this['topic']->bindEvent('topic.post', function ($post, $postUrl) {
trace_log('A post has been submitted at '.$postUrl);
});
}
@@ -279,7 +279,7 @@ class Plugin extends PluginBase

public function boot()
{
Event::listen('backend.menu.extendItems', function($manager) {
Event::listen('backend.menu.extendItems', function ($manager) {

$manager->addMainMenuItems('Winter.Cms', [
'cms' => [
@@ -301,7 +301,7 @@ class Plugin extends PluginBase
Similarly we can remove the menu items with the same event:

```php
Event::listen('backend.menu.extendItems', function($manager) {
Event::listen('backend.menu.extendItems', function ($manager) {

$manager->removeMainMenuItem('Winter.Cms', 'cms');
$manager->removeSideMenuItem('Winter.Cms', 'cms', 'pages');
10 changes: 5 additions & 5 deletions plugin/registration.md
Original file line number Diff line number Diff line change
@@ -219,7 +219,7 @@ The `boot` method is called after all services are loaded and all plugins are re
```php
public function boot()
{
User::extend(function($model) {
User::extend(function ($model) {
$model->hasOne['author'] = ['Acme\Blog\Models\Author'];
});
}
@@ -230,8 +230,8 @@ The `boot` and `register` methods are not called during the update process, or w
Plugins can also supply a file named **routes.php** that may contain custom routing logic, as defined in the [router service](../services/router). For example:

```php
Route::group(['prefix' => 'api_acme_blog'], function() {
Route::get('cleanup_posts', function(){ return Posts::cleanUp(); });
Route::group(['prefix' => 'api_acme_blog'], function () {
Route::get('cleanup_posts', function (){ return Posts::cleanUp(); });
});
```

@@ -288,7 +288,7 @@ public function registerMarkupTags()
'form_open' => ['Winter\Storm\Html\Form', 'open'],

// Using an inline closure
'helloWorld' => function() { return 'Hello World!'; },
'helloWorld' => function () { return 'Hello World!'; },

// Any callable with custom options defined - named 'callable' method
'goodbyeWorld' => [
@@ -388,7 +388,7 @@ To register a custom middleware, you can apply it directly to a backend controll
```php
public function boot()
{
\Cms\Classes\CmsController::extend(function($controller) {
\Cms\Classes\CmsController::extend(function ($controller) {
$controller->middleware('Path\To\Custom\Middleware');
});
}
6 changes: 3 additions & 3 deletions services/application.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ The inversion of control (IoC) container is a tool for managing class dependenci
There are two ways the IoC container can resolve dependencies: via Closure callbacks or automatic resolution. First, we'll explore Closure callbacks. First, a "type" may be bound into the container:

```php
App::bind('foo', function($app) {
App::bind('foo', function ($app) {
return new FooBar;
});
```
@@ -27,7 +27,7 @@ When the `App::make` method is called, the Closure callback is executed and the
Sometimes you may wish to bind something into the container that should only be resolved once, and the same instance should be returned on subsequent calls into the container:

```php
App::singleton('foo', function() {
App::singleton('foo', function () {
return new FooBar;
});
```
@@ -80,7 +80,7 @@ class FooServiceProvider extends ServiceProvider

public function register()
{
$this->app->bind('foo', function() {
$this->app->bind('foo', function () {
return new Foo;
});
}
16 changes: 8 additions & 8 deletions services/behaviors.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ Post::extend(function ($model) {
$model->addDynamicProperty('tagsCache', null);

// Add a new method to the class
$model->addDynamicMethod('getTagsAttribute', function() use ($model) {
$model->addDynamicMethod('getTagsAttribute', function () use ($model) {
if ($model->tagsCache) {
return $model->tagsCache;
} else {
@@ -175,7 +175,7 @@ class Plugin extends PluginBase
Properties can be declared on an extendable object by calling `addDynamicProperty` and passing a property name and value.

```php
Post::extend(function($model) {
Post::extend(function ($model) {
$model->addDynamicProperty('tagsCache', null);
});
```
@@ -207,10 +207,10 @@ $model->getDynamicProperties()[$key];
Methods can be created to an extendable object by calling `addDynamicMethod` and passing a method name and callable object, like a `Closure`.

```php
Post::extend(function($model) {
Post::extend(function ($model) {
$model->addDynamicProperty('tagsCache', null);

$model->addDynamicMethod('getTagsAttribute', function() use ($model) {
$model->addDynamicMethod('getTagsAttribute', function () use ($model) {
if ($model->tagsCache) {
return $model->tagsCache;
} else {
@@ -225,7 +225,7 @@ Post::extend(function($model) {
You can check for the existence of a method in an `Extendable` class by using the `methodExists` method - similar to the PHP `method_exists()` function. This will detect both standard methods and dynamic methods that have been added through a `addDynamicMethod` call. `methodExists` accepts one parameter: a string of the method name to check the existence of.

```php
Post::extend(function($model) {
Post::extend(function ($model) {
$model->addDynamicMethod('getTagsAttribute', function () use ($model) {
return $model->tagsCache;
});
@@ -242,7 +242,7 @@ $post->methodExists('missingMethod'); // false
To retrieve a list of all available methods in an `Extendable` class, you can use the `getClassMethods` method. This method operates similar to the PHP `get_class_methods()` function in that it returns an array of available methods in a class, but in addition to defined methods in the class, it will also list any methods provided by an extension or through an `addDynamicMethod` call.

```php
Post::extend(function($model) {
Post::extend(function ($model) {
$model->addDynamicMethod('getTagsAttribute', function () use ($model) {
return $model->tagsCache;
});
@@ -270,7 +270,7 @@ This unique ability to extend constructors allows behaviors to be implemented dy
/**
* Extend the Winter.Users Users controller to include the RelationController behavior too
*/
Winter\Users\Controllers\Users::extend(function($controller) {
Winter\Users\Controllers\Users::extend(function ($controller) {
// Implement the list controller behavior dynamically
$controller->implement[] = \Backend\Behaviors\RelationController::class;

@@ -400,7 +400,7 @@ $controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class);
Below is an example of dynamically extending a `UsersController` of a third-party plugin utilizing this method to avoid preventing other plugins from also extending the afore-mentioned third-party plugin.

```php
UsersController::extend(function($controller) {
UsersController::extend(function ($controller) {
// Implement behavior if not already implemented
if (!$controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class)) {
$controller->implement[] = \Backend\Behaviors\RelationController::class;
Loading