Skip to content

Commit

Permalink
MNT Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 7, 2023
1 parent 4f79962 commit 454ba5e
Show file tree
Hide file tree
Showing 148 changed files with 5,124 additions and 3,141 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ rules.overrides = [
impliedStrict: true
}
},
settings: {
react: {
version: '16'
}
},
rules: {
// These rules are not appropriate for linting markdown code blocks
'lines-around-comment': 'off',
'import/no-unresolved': 'off',
'import/extensions': 'off',
'react/jsx-no-undef': 'off',
'no-undef': 'off',
'no-unused-expressions': 'off',
'no-unused-vars': 'off',
'brace-style': 'off', // it's useful to have comments before the else block
// These rules are disabled because they are difficult to adhere to right now
'jsx-a11y/label-has-associated-control': 'off',
'react/prefer-stateless-function': 'off',
}
}
];
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
}
],
"require-dev": {
"silverstripe/markdown-php-codesniffer": "dev-pulls/1/new-repo"
"silverstripe/markdown-php-codesniffer": "dev-pulls/1/new-repo",
"slevomat/coding-standard": "^8.14"
},
"repositories": [
{
"url": "https://github.com/creative-commoners/markdown-php-codesniffer",
"type": "vcs"
}
]
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
4 changes: 3 additions & 1 deletion en/00_Getting_Started/00_Server_Requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ Silverstripe CMS uses SwiftMailer to send email messages. New installations setu
You _must_ ensure emails are being sent from your _production_ environment. You can do this by testing that the ***Lost password*** form available at `/Security/lostpassword` sends an email to your inbox, or with the following code snippet that can be run via a `SilverStripe\Dev\BuildTask`:
```php
$email = new SilverStripe\Control\Email\Email('[email protected]', '[email protected]', 'My test subject', 'My email body text');
use SilverStripe\Control\Email\Email;
$email = Email::create('[email protected]', '[email protected]', 'My test subject', 'My email body text');
$email->send();
```

Expand Down
94 changes: 55 additions & 39 deletions en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ along with any [relationships](relations) defined as `$has_one`, `$has_many`, `$

Let's look at a simple example:

**app/src/Player.php**
**app/src/Model/Player.php**

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{
private static $db = [
'PlayerNumber' => 'Int',
'FirstName' => 'Varchar(255)',
'LastName' => 'Text',
'Birthday' => 'Date'
'Birthday' => 'Date',
];
}
```
Expand Down Expand Up @@ -76,18 +78,22 @@ automatically set on the `DataObject`.
* Created: A date/time field set to the creation date of this record
* LastEdited: A date/time field set to the date this record was last edited through `write()`

**app/src/Player.php**
**app/src/Model/Player.php**

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{
private static string $table_name = 'Player';

private static $db = [
'PlayerNumber' => 'Int',
'FirstName' => 'Varchar(255)',
'LastName' => 'Text',
'Birthday' => 'Date'
'Birthday' => 'Date',
];
}
```
Expand Down Expand Up @@ -133,7 +139,7 @@ Database columns and properties can be set as class properties on the object. Th
of the values through a custom `__set()` method.

```php
$player->FirstName = "Sam";
$player->FirstName = 'Sam';
$player->PlayerNumber = 07;
```

Expand Down Expand Up @@ -175,11 +181,10 @@ are `filter()` and `sort()`:

```php
$members = Player::get()->filter([
'FirstName' => 'Sam'
'FirstName' => 'Sam',
])->sort('Surname');

// returns a `DataList` containing all the `Player` records that have the `FirstName` of 'Sam'

```

[info]
Expand All @@ -201,7 +206,7 @@ result set in PHP. In `MySQL` the query generated by the ORM may look something

```php
$players = Player::get()->filter([
'FirstName' => 'Sam'
'FirstName' => 'Sam',
]);

$players = $players->sort('Surname');
Expand All @@ -214,7 +219,7 @@ This also means that getting the count of a list of objects will be done with a

```php
$players = Player::get()->filter([
'FirstName' => 'Sam'
'FirstName' => 'Sam',
])->sort('Surname');

// This will create an single SELECT COUNT query
Expand All @@ -229,7 +234,7 @@ echo $players->Count();
```php
$players = Player::get();

foreach($players as $player) {
foreach ($players as $player) {
echo $player->FirstName;
}
```
Expand All @@ -239,7 +244,7 @@ Notice that we can step into the loop safely without having to check if `$player
```php
$players = Player::get();

if($players->exists()) {
if ($players->exists()) {
// do something here
}
```
Expand Down Expand Up @@ -291,14 +296,14 @@ However you might have several entries with the same `FirstName` and would like
```php
$players = Players::get()->sort([
'FirstName' => 'ASC',
'LastName'=>'ASC'
'LastName' => 'ASC',
]);
```

You can also sort randomly. Using the `DB` class, you can get the random sort method per database type.

```php
$random = DB::get_conn()->random();
$random = DB::get_conn()->random();
$players = Player::get()->sort($random);
```

Expand All @@ -308,7 +313,7 @@ The `filter()` method filters the list of objects that gets returned.

```php
$players = Player::get()->filter([
'FirstName' => 'Sam'
'FirstName' => 'Sam',
]);
```

Expand Down Expand Up @@ -338,9 +343,7 @@ $players = Player::get()->filter('FirstName', 'Sam');
Or if you want to find both Sam and Sig.

```php
$players = Player::get()->filter(
'FirstName', ['Sam', 'Sig']
);
$players = Player::get()->filter('FirstName', ['Sam', 'Sig']);

// SELECT * FROM Player WHERE FirstName IN ('Sam', 'Sig')
```
Expand Down Expand Up @@ -461,7 +464,7 @@ for each record, if the callback returns true, this record will be added to the
The below example will get all `Players` aged over 10.

```php
$players = Player::get()->filterByCallback(function($item, $list) {
$players = Player::get()->filterByCallback(function ($item, $list) {
return ($item->Age() > 10);
});
```
Expand All @@ -480,7 +483,7 @@ Remove both Sam and Sig..

```php
$players = Player::get()->exclude([
'FirstName' => ['Sam','Sig']
'FirstName' => ['Sam','Sig'],
]);
```

Expand Down Expand Up @@ -508,7 +511,7 @@ And removing Sig and Sam with that are either age 17 or 43.
```php
$players = Player::get()->exclude([
'FirstName' => ['Sam', 'Sig'],
'Age' => [17, 43]
'Age' => [17, 43],
]);

// SELECT * FROM Player WHERE ("FirstName" NOT IN ('Sam','Sig) OR "Age" NOT IN ('17', '43'));
Expand All @@ -519,7 +522,7 @@ You can use [SearchFilters](searchfilters) to add additional behavior to your `e
```php
$players = Player::get()->exclude([
'FirstName:EndsWith' => 'S',
'PlayerNumber:LessThanOrEqual' => '10'
'PlayerNumber:LessThanOrEqual' => '10',
]);
```

Expand Down Expand Up @@ -576,9 +579,10 @@ For instance, the below model will be stored in the table name `BannerImage`

```php
namespace SilverStripe\BannerManager;

use SilverStripe\ORM\DataObject;

class BannerImage extends DataObject
class BannerImage extends DataObject
{
private static $table_name = 'BannerImage';
}
Expand Down Expand Up @@ -612,13 +616,13 @@ table and column.


```php
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Queries\SQLSelect;

public function countDuplicates($model, $fieldToCheck)
public function countDuplicates($model, $fieldToCheck)
{
$table = DataObject::getSchema()->tableForField($model, $field);
$query = new SQLSelect();
$query = SQLSelect::create();
$query->setFrom("\"{$table}\"");
$query->setWhere(["\"{$table}\".\"{$field}\"" => $model->$fieldToCheck]);
return $query->count();
Expand Down Expand Up @@ -656,10 +660,10 @@ You can specify a join with the `innerJoin` and `leftJoin` methods. Both of the
```php
// Without an alias
$members = Member::get()
->leftJoin("Group_Members", "\"Group_Members\".\"MemberID\" = \"Member\".\"ID\"");
->leftJoin('Group_Members', '"Group_Members"."MemberID" = "Member"."ID"');

$members = Member::get()
->innerJoin("Group_Members", "\"Rel\".\"MemberID\" = \"Member\".\"ID\"", "Rel");
->innerJoin('Group_Members', '"Rel"."MemberID" = "Member"."ID"', 'Rel');
```

[alert]
Expand All @@ -673,13 +677,14 @@ Define the default values for all the `$db` fields. This example sets the "Statu
whenever a new object is created.

```php
namespace App\Model;

use SilverStripe\ORM\DataObject;

class Player extends DataObject
class Player extends DataObject
{

private static $defaults = [
"Status" => 'Active',
'Status' => 'Active',
];
}
```
Expand All @@ -698,16 +703,26 @@ time.
For example, suppose we have the following set of classes:

```php
use SilverStripe\CMS\Model\SiteTree;
namespace {

class Page extends SiteTree
{
use SilverStripe\CMS\Model\SiteTree;

class Page extends SiteTree
{
// ...
}
}
class NewsPage extends Page
```

```php
namespace App\PageType;

use Page;

class NewsPage extends Page
{
private static $db = [
'Summary' => 'Text'
'Summary' => 'Text',
];
}
```
Expand All @@ -722,7 +737,8 @@ SilverStripe\CMS\Model\SiteTree:
LastEdited: Datetime
Title: Varchar
Content: Text
NewsPage:

App\PageType\NewsPage:
ID: Int
Summary: Text
```
Expand All @@ -732,7 +748,7 @@ Accessing the data is transparent to the developer.
```php
$news = NewsPage::get();

foreach($news as $article) {
foreach ($news as $article) {
echo $article->Title;
}
```
Expand Down
Loading

0 comments on commit 454ba5e

Please sign in to comment.