Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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/test-rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- app
- system
- tests
- utils/Rector
- utils
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions app/Views/errors/html/production.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="robots" content="noindex">

<title>Whoops!</title>
<title><?= lang('Errors.whoops') ?></title>

<style type="text/css">
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug.css')) ?>
Expand All @@ -14,9 +14,9 @@

<div class="container text-center">

<h1 class="headline">Whoops!</h1>
<h1 class="headline"><?= lang('Errors.whoops') ?></h1>

<p class="lead">We seem to have hit a snag. Please try again later...</p>
<p class="lead"><?= lang('Errors.weHitASnag') ?></p>

</div>

Expand Down
7 changes: 6 additions & 1 deletion contributing/pull_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ The best way to contribute is to fork the CodeIgniter4 repository, and "clone" t
- `> cd CodeIgniter4/`
- `> composer update`
6. Create a new [branch](https://help.github.com/en/articles/about-branches) in your project for each set of changes you want to make.
- `> git checkout -b <new-branch-name>`
- If your PR is for bug fixes:
- `> git switch develop`
- `> git switch -c <new-branch-name>`
- If your PR has any enhancement, create new branch from next minor version branch, e.g. __"4.3"__:
- `> git switch <next-minor-version-branch>`
- `> git switch -c <new-branch-name>`
7. Fix existing bugs on the [Issue tracker](https://github.com/codeigniter4/CodeIgniter4/issues) after confirming that no one else is working on them.
8. [Commit](https://help.github.com/en/desktop/contributing-to-projects/committing-and-reviewing-changes-to-your-project) the changed files in your contribution branch.
- `> git commit`
Expand Down
107 changes: 71 additions & 36 deletions contributing/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ ORIGIN\_URL.

Clone your repository, leaving a local folder for you to work with:

cd ALL_PROJECTS
git clone ORIGIN_URL
```console
> cd ALL_PROJECTS
> git clone ORIGIN_URL
```

## Syncing your repository

Expand All @@ -72,16 +74,20 @@ an alias for the shared repository as well, so that you can "synch" the
two, making sure that your repository includes any other contributions
that have been merged by us into the shared repo:

git remote add upstream UPSTREAM_URL
```console
> git remote add upstream UPSTREAM_URL
```

Then synchronizing is done by pulling from us and pushing to you. This
is normally done locally, so that you can resolve any merge conflicts.
For instance, to synchronize **develop** branches:

git switch develop
git fetch upstream
git merge upstream/develop
git push origin develop
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```

You might get merge conflicts when you merge. It is your
responsibility to resolve those locally, so that you can continue
Expand All @@ -105,12 +111,25 @@ This local branch should be named appropriately, for instance
"fix/problem123" or "new/mind-reader". The slashes in these branch names
is optional, and implies a sort of namespacing if used.

For instance, make sure you are in the *develop* branch, and create a
new feature branch, based on *develop*, for a new feature you are
- All bug fix PRs should be sent to the __"develop"__ branch, this is where the next bug fix version will be developed.
- PRs with any enhancement should be sent to next minor version branch, e.g. __"4.3"__

For instance, if you send a PR to __"develop"__ branch, make sure you are in the *develop* branch, and create a
new bugfix branch, based on *develop*, for a new feature you are
creating:

git switch develop
git switch -c new/mind-reader
```console
> git switch develop
> git switch -c fix/problem123
```

If you send a PR with an enhancement, make sure you are in the *next minor version* branch,
and create a new feature branch, based on, e.g., *4.3*, for a new feature you are creating:

```console
> git switch 4.3
> git switch -c new/mind-reader
```

Saving changes only updates your local working area.

Expand All @@ -123,23 +142,27 @@ in.
You can have as many commits in a branch as you need to "get it right".
For instance, to commit your work from a debugging session:

git add .
git commit -S -m "Find and fix the broken reference problem"
```console
> git add .
> git commit -S -m "Find and fix the broken reference problem"
```

Just make sure that your commits in a feature branch are all related.

If you are working on two features at a time, then you will want to
switch between them to keep the contributions separate. For instance:

git switch new/mind-reader
// work away
git add .
git commit -S -m "Added adapter for abc"
git switch fix/issue-123
// work away
git add .
git commit -S -m "Fixed problem in DEF\Something"
git switch develop
```console
> git switch new/mind-reader
> ## work away
> git add .
> git commit -S -m "Added adapter for abc"
> git switch fix/issue-123
> ## work away
> git add .
> git commit -S -m "Fixed problem in DEF\Something"
> git switch develop
```

The last checkout makes sure that you end up in your *develop* branch as
a starting point for your next session working with your repository.
Expand All @@ -157,19 +180,25 @@ It is a lot easier to resolve conflicts at this stage.

Synchronize your repository:

git switch develop
git fetch upstream
git merge upstream/develop
git push origin develop
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```

Bring your feature branch up to date:

git switch new/mind-reader
git rebase upstream/develop
```console
> git switch fix/issue-123
> git rebase upstream/develop
```

And finally push your local branch to your GitHub repository:

git push --force-with-lease origin new/mind-reader
```console
> git push --force-with-lease origin fix/issue-123
```

## Pull Requests

Expand Down Expand Up @@ -223,23 +252,29 @@ do the following:

Synchronize your repository:

git switch develop
git fetch upstream
git merge upstream/develop
git push origin develop
```console
> git switch develop
> git fetch upstream
> git merge upstream/develop
> git push origin develop
```

Bring your feature branch up to date:

git switch new/mind-reader
git rebase upstream/develop
```console
> git switch fix/problem123
> git rebase upstream/develop
```

You might get conflicts when you rebase. It is your
responsibility to resolve those locally, so that you can continue
collaborating with the shared repository.

And finally push your local branch to your GitHub repository:

git push --force-with-lease origin new/mind-reader
```console
> git push --force-with-lease origin fix/problem123
```

## Cleanup

Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
$rectorConfig->parallel();

// paths to refactor; solid alternative to CLI arguments
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils/Rector']);
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']);

// do you need to include constants, class aliases or custom autoloader? files listed will be executed
$rectorConfig->bootstrapFiles([
Expand Down
9 changes: 6 additions & 3 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1878,11 +1878,13 @@ public function getCompiledInsert(bool $reset = true)
/**
* Compiles an insert string and runs the query
*
* @param array|object|null $set
*
* @throws DatabaseException
*
* @return bool|Query
*/
public function insert(?array $set = null, ?bool $escape = null)
public function insert($set = null, ?bool $escape = null)
{
if ($set !== null) {
$this->set($set, '', $escape);
Expand Down Expand Up @@ -2012,11 +2014,12 @@ public function getCompiledUpdate(bool $reset = true)
/**
* Compiles an update string and runs the query.
*
* @param mixed $where
* @param array|object|null $set
* @param array|RawSql|string|null $where
*
* @throws DatabaseException
*/
public function update(?array $set = null, $where = null, ?int $limit = null): bool
public function update($set = null, $where = null, ?int $limit = null): bool
{
if ($set !== null) {
$this->set($set);
Expand Down
16 changes: 16 additions & 0 deletions system/Language/en/Errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

// Errors language settings
return [
'whoops' => 'Whoops!',
'weHitASnag' => 'We seem to have hit a snag. Please try again later...',
];
28 changes: 27 additions & 1 deletion tests/system/Database/Builder/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
$this->db = new MockConnection([]);
}

public function testSimpleInsert()
public function testInsertArray()
{
$builder = $this->db->table('jobs');

Expand All @@ -59,6 +59,32 @@ public function testSimpleInsert()
$this->assertSame($expectedBinds, $builder->getBinds());
}

public function testInsertObject()
{
$builder = $this->db->table('jobs');

$insertData = (object) [
'id' => 1,
'name' => 'Grocery Sales',
];
$builder->testMode()->insert($insertData, true);

$expectedSQL = 'INSERT INTO "jobs" ("id", "name") VALUES (1, \'Grocery Sales\')';
$expectedBinds = [
'id' => [
1,
true,
],
'name' => [
'Grocery Sales',
true,
],
];

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledInsert()));
$this->assertSame($expectedBinds, $builder->getBinds());
}

public function testThrowsExceptionOnNoValuesSet()
{
$builder = $this->db->table('jobs');
Expand Down
28 changes: 26 additions & 2 deletions tests/system/Database/Builder/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,35 @@ protected function setUp(): void
$this->db = new MockConnection([]);
}

public function testUpdate()
public function testUpdateArray()
{
$builder = new BaseBuilder('jobs', $this->db);

$builder->testMode()->where('id', 1)->update(['name' => 'Programmer'], null, null);
$data = ['name' => 'Programmer'];
$builder->testMode()->where('id', 1)->update($data, null, null);

$expectedSQL = 'UPDATE "jobs" SET "name" = \'Programmer\' WHERE "id" = 1';
$expectedBinds = [
'id' => [
1,
true,
],
'name' => [
'Programmer',
true,
],
];

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledUpdate()));
$this->assertSame($expectedBinds, $builder->getBinds());
}

public function testUpdateObject()
{
$builder = new BaseBuilder('jobs', $this->db);

$data = (object) ['name' => 'Programmer'];
$builder->testMode()->where('id', 1)->update($data, null, null);

$expectedSQL = 'UPDATE "jobs" SET "name" = \'Programmer\' WHERE "id" = 1';
$expectedBinds = [
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.2.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ BREAKING

- Now ``Services::request()`` returns ``IncomingRequest`` or ``CLIRequest``.
- The method signature of ``CodeIgniter\Debug\Exceptions::__construct()`` has been changed. The ``IncomingRequest`` typehint on the ``$request`` parameter was removed. Extending classes should likewise remove the parameter so as not to break LSP.
- The method signature of ``BaseBuilder.php::insert()`` and ``BaseBuilder.php::update()`` have been changed. The ``?array`` typehint on the ``$set`` parameter was removed.

Enhancements
************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

final class CheckFrameworkExceptionInstantiationViaNamedConstructorRule implements Rule
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'FrameworkException instance creation via new expression is not allowed, use its named constructor instead';

public function getNodeType(): string
Expand Down
9 changes: 1 addition & 8 deletions utils/PHPStan/CheckUseStatementsAfterLicenseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@

final class CheckUseStatementsAfterLicenseRule implements Rule
{
/**
* @var string
*/
private const ERROR_MESSAGE = 'Use statement must be located after license docblock';

/**
* @var string
*/
private const ERROR_MESSAGE = 'Use statement must be located after license docblock';
private const COPYRIGHT_REGEX = '/\* \(c\) CodeIgniter Foundation <admin@codeigniter\.com>/m';

public function getNodeType(): string
Expand Down
Loading