Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
82085f2
feat: add Database\DataConverter class
kenjis Nov 18, 2023
69dd4cc
chore: adds skip_violations
kenjis Nov 18, 2023
caf51d4
refactor: use get_debug_type() instead of var_export()
kenjis Nov 20, 2023
8554b71
test: extract createDataConverter()
kenjis Nov 22, 2023
c15bbbe
refactor: fix PHPStan types
kenjis Nov 22, 2023
caa43a0
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 22, 2023
cf3bb3f
docs: fix doc comment DB column type
kenjis Nov 22, 2023
e040667
docs: fix PHPDoc types
kenjis Nov 23, 2023
479d3fb
feat: improve error messages
kenjis Nov 23, 2023
83574ab
refactor: use var_export()
kenjis Nov 23, 2023
323a3d3
refactor: use static::class
kenjis Nov 23, 2023
3447d01
docs: add {@inheritDoc}
kenjis Nov 23, 2023
943599b
docs: fix TDbColumn type
kenjis Nov 23, 2023
8630f5d
fix: remove uneeded if conditions
kenjis Nov 23, 2023
75b16ae
docs: improve doc comments for conversions
kenjis Nov 23, 2023
c2ddfe9
docs: remove {@inheritDoc}
kenjis Nov 23, 2023
905a1a5
refactor: rename method names
kenjis Nov 23, 2023
938ae6e
refactor: change namespace to CodeIgniter\DataConverter
kenjis Nov 24, 2023
e42704d
feat: datetime supports format
kenjis Nov 24, 2023
7e4049e
refactor: rename variable names
kenjis Nov 24, 2023
4cafb96
feat: add nullable check
kenjis Nov 24, 2023
896cca5
chore: vendor/bin/psalm --set-baseline=psalm-baseline.xml
kenjis Nov 26, 2023
c7b6760
refactor: add `declare(strict_types=1)`
kenjis Dec 7, 2023
aee23f3
docs: improve comments
kenjis Dec 28, 2023
38a88c9
docs: update comments in Entity/Cast/CastInterface
kenjis Jan 23, 2024
f2417d3
refactor: make method names to be same as Entity CastInterface
kenjis Jan 23, 2024
8200f8e
refactor: move DataConverter/Cast to DataCaster/Cast
kenjis Jan 23, 2024
e98c902
feat: add DataCaster class
kenjis Jan 23, 2024
ac9c536
refactor: use DataCaster in DataConverter
kenjis Jan 23, 2024
31d8d79
refactor: use DataCaster in Entity
kenjis Jan 23, 2024
dd44603
chore: update phpstan-baseline
kenjis Jan 23, 2024
868402d
chore: update deptrac.yaml
kenjis Jan 23, 2024
07e8b63
chore: update psalm-baseline
kenjis Jan 23, 2024
590f580
test: add missing parent::__construct()
kenjis Jan 23, 2024
942eddb
docs: remove PHPDoc @template
kenjis Jan 23, 2024
567372e
docs: make @param more strict
kenjis Jan 23, 2024
029d118
docs: fix doc comments in Entity/Cast/CastInterface
kenjis Jan 29, 2024
7199ac4
docs: update @param style
kenjis Jan 29, 2024
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
19 changes: 19 additions & 0 deletions deptrac.yaml
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,14 @@ parameters:
collectors:
- type: className
regex: ^Codeigniter\\Database\\.*
- name: DataCaster
collectors:
- type: className
regex: ^Codeigniter\\DataCaster\\.*
- name: DataConverter
collectors:
- type: className
regex: ^Codeigniter\\DataConverter\\.*
- name: Email
collectors:
- type: className
Expand DownExpand Up@@ -166,10 +174,16 @@ parameters:
- Entity
- Events
- I18n
DataCaster:
- I18n
- URI
DataConverter:
- DataCaster
Email:
- I18n
- Events
Entity:
- DataCaster
- I18n
Files:
- I18n
Expand DownExpand Up@@ -228,6 +242,11 @@ parameters:
- CodeIgniter\HTTP\Header
- CodeIgniter\HTTP\IncomingRequest
- CodeIgniter\HTTP\ResponseInterface
CodeIgniter\DataCaster\DataCaster:
- CodeIgniter\Entity\Cast\CastInterface
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\DataCaster\Exceptions\CastException:
- CodeIgniter\Entity\Exceptions\CastException
CodeIgniter\Entity\Cast\URICast:
- CodeIgniter\HTTP\URI
CodeIgniter\Log\Handlers\ChromeLoggerHandler:
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1318,7 +1318,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'count' => 1,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
Expand Down
40 changes: 1 addition & 39 deletions psalm-baseline.xml
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, ParserCallableString>]]></code>
Expand All@@ -26,12 +26,6 @@
<code>Memcache|Memcached</code>
</UndefinedDocblockClass>
</file>
<file src="system/Commands/Utilities/Routes/ControllerMethodReader.php">
<DuplicateArrayKey>
<code>$routeWithoutController</code>
<code>$routeWithoutController</code>
</DuplicateArrayKey>
</file>
<file src="system/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -91,15 +85,6 @@
<code><![CDATA[$this->db->transStatus]]></code>
</InaccessibleProperty>
</file>
<file src="system/Database/OCI8/Connection.php">
<UndefinedConstant>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_COMMIT_ON_SUCCESS</code>
<code>OCI_NO_AUTO_COMMIT</code>
<code>SQLT_CHR</code>
</UndefinedConstant>
</file>
<file src="system/Debug/Toolbar/Views/toolbar.tpl.php">
<InaccessibleMethod>
<code>renderTimeline</code>
Expand DownExpand Up@@ -132,11 +117,6 @@
<code>#[ReturnTypeWillChange]</code>
</MissingImmutableAnnotation>
</file>
<file src="system/Test/ControllerResponse.php">
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$this->dom = &$this->domParser]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
<file src="system/View/Parser.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, array<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand DownExpand Up@@ -164,11 +144,6 @@
<code>$this</code>
</InvalidScope>
</file>
<file src="tests/system/CLI/ConsoleTest.php">
<DuplicateArrayKey>
<code>$command</code>
</DuplicateArrayKey>
</file>
<file src="tests/system/CommonFunctionsTest.php">
<UndefinedClass>
<code>UnexsistenceClass</code>
Expand All@@ -181,19 +156,6 @@
<code><![CDATA['Config\TestRegistrar']]></code>
</UndefinedClass>
</file>
<file src="tests/system/Database/BaseConnectionTest.php">
<InaccessibleProperty>
<code><![CDATA[$db->username]]></code>
<code><![CDATA[$db->username]]></code>
</InaccessibleProperty>
</file>
<file src="tests/system/Database/Live/OCI8/CallStoredProcedureTest.php">
<UndefinedConstant>
<code>OCI_ASSOC</code>
<code>OCI_B_CURSOR</code>
<code>OCI_RETURN_NULLS</code>
</UndefinedConstant>
</file>
<file src="tests/system/Entity/EntityTest.php">
<EmptyArrayAccess>
<code>$current[$key]</code>
Expand Down
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/ArrayCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class ArrayCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class ArrayCast extends BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

if ((strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
}

public static function set(mixed $value, array $params = []): string
{
return serialize($value);
}
}
39 changes: 39 additions & 0 deletions system/DataCaster/Cast/BaseCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use TypeError;

abstract class BaseCast implements CastInterface
{
public static function get(mixed $value, array $params = []): mixed
{
return $value;
}

public static function set(mixed $value, array $params = []): mixed
{
return $value;
}

protected static function invalidTypeValueError(mixed $value): never
{
$message = '[' . static::class . '] Invalid value type: ' . get_debug_type($value);
if (is_scalar($value)) {
$message .= ', and its value: ' . var_export($value, true);
}

throw new TypeError($message);
}
}
36 changes: 36 additions & 0 deletions system/DataCaster/Cast/BooleanCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class BooleanCast
*
* (PHP) [bool --> bool ] --> (DB driver) --> (DB column) bool|int(0/1)
* [ <-- string|int] <-- (DB driver) <-- (DB column) bool|int(0/1)
*/
class BooleanCast extends BaseCast
{
public static function get(mixed $value, array $params = []): bool
{
// For PostgreSQL
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}
41 changes: 41 additions & 0 deletions system/DataCaster/Cast/CSVCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

/**
* Class CSVCast
*
* (PHP) [array --> string] --> (DB driver) --> (DB column) string
* [ <-- string] <-- (DB driver) <-- (DB column) string
*/
class CSVCast extends BaseCast
{
public static function get(mixed $value, array $params = []): array
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

return explode(',', $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! is_array($value)) {
self::invalidTypeValueError($value);
}

return implode(',', $value);
}
}
37 changes: 37 additions & 0 deletions system/DataCaster/Cast/CastInterface.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

interface CastInterface
{
/**
* Takes a value from DataSource, returns its value for PHP.
*
* @param mixed $value Data from database driver
* @param list<string> $params Additional param
*
* @return mixed PHP native value
*/
public static function get(mixed $value, array $params = []): mixed;

/**
* Takes a PHP value, returns its value for DataSource.
*
* @param mixed $value PHP native value
* @param list<string> $params Additional param
*
* @return mixed Data to pass to database driver
*/
public static function set(mixed $value, array $params = []): mixed;
}
48 changes: 48 additions & 0 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

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

namespace CodeIgniter\DataCaster\Cast;

use CodeIgniter\I18n\Time;

/**
* Class DatetimeCast
*
* (PHP) [Time --> string] --> (DB driver) --> (DB column) datetime
* [ <-- string] <-- (DB driver) <-- (DB column) datetime
*/
class DatetimeCast extends BaseCast
{
public static function get(mixed $value, array $params = []): Time
{
if (! is_string($value)) {
self::invalidTypeValueError($value);
}

/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = $params[0] ?? 'Y-m-d H:i:s';

return Time::createFromFormat($format, $value);
}

public static function set(mixed $value, array $params = []): string
{
if (! $value instanceof Time) {
self::invalidTypeValueError($value);
}

return (string) $value;
}
}
Loading