Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would want to switch to PHP 8.1 for static analysis and other common stages, but there are branch protection rules that demand PHP 7.4. So let's add 8.1 first and tweak the protections later.


steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.1"

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.2"
- "8.4"

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'blank_line_after_opening_tag' => false,
'linebreak_after_opening_tag' => false,
'blank_line_between_import_groups' => false,
'nullable_type_declaration_for_default_null_value' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function __construct(string $identity)
/** @inheritDoc */
protected function _enumerate(
int $count,
StreamCursor $cursor = null,
StreamTracer $tracer = null,
?StreamCursor $cursor = null,
?StreamTracer $tracer = null,
?EnumerationOptions $option = null
): StreamResult {
if (!$cursor instanceof TrendingTopicStreamCursor) {
Expand Down
1 change: 1 addition & 0 deletions extras/phpcs/TumblrApp/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
</properties>
</rule>
<rule ref="SlevomatCodingStandard.PHP.ShortList" />
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="declareOnFirstLine" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/Tumblr/StreamBuilder/Codec/Codec.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class Codec
* @param CacheProvider|null $cache_provider The cache provider used to deserialize a template.
* @see @StreamContext, there are stuff from stream are cached during the to_template process.
*/
public function __construct(CacheProvider $cache_provider = null)
public function __construct(?CacheProvider $cache_provider = null)
{
$this->cache_provider = $cache_provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InvalidStreamArrayException extends \InvalidArgumentException
/**
* @param array|null $stream_array The stream_array which is sent to the deserializer
*/
public function __construct(array $stream_array = null)
public function __construct(?array $stream_array = null)
{
parent::__construct(sprintf(
'Invalid stream array: %s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TemplateNotFoundException extends \InvalidArgumentException
* @param int $code The exception code.
* @param \Throwable $previous The previous exception.
*/
public function __construct($message = "Template not found", $code = 404, \Throwable $previous = null)
public function __construct($message = "Template not found", $code = 404, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function __construct(
int $fencepost_timestamp_ms,
int $region,
int $head_offset,
StreamCursor $tail_cursor = null,
StreamCursor $inject_cursor = null
?StreamCursor $tail_cursor = null,
?StreamCursor $inject_cursor = null
) {
if ($region !== self::REGION_INJECT && is_null($tail_cursor)) {
throw new \InvalidArgumentException('Head or Tail region must contains tail_cursor');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ abstract protected function get_fence_id_str(): string;
*/
protected function _enumerate(
int $count,
StreamCursor $cursor = null,
StreamTracer $tracer = null,
?StreamCursor $cursor = null,
?StreamTracer $tracer = null,
?EnumerationOptions $option = null
): StreamResult {
if (!(is_null($cursor) || ($cursor instanceof FencepostCursor))) {
Expand Down Expand Up @@ -195,7 +195,7 @@ protected function _enumerate(
* @param EnumerationOptions|null $option The option on enumeration
* @return array [Fencepost|null, FencepostRankedStreamCursor|null]
*/
private function setup_enumeration(FencepostCursor $in_cursor = null, StreamTracer $tracer = null, ?EnumerationOptions $option = null)
private function setup_enumeration(?FencepostCursor $in_cursor = null, ?StreamTracer $tracer = null, ?EnumerationOptions $option = null)
{
if (!is_null($in_cursor)) {
// you already have a cursor, try to turn it into a fencepost:
Expand Down Expand Up @@ -287,7 +287,7 @@ private function setup_enumeration_from_existing_fencepost(
private function setup_enumeration_from_new_fencepost(
?StreamTracer $tracer,
int $now_ms,
int $latest_ms = null,
?int $latest_ms = null,
?EnumerationOptions $option = null
): array {
$fencepost = $this->commit_new_fencepost($now_ms, $latest_ms, $tracer, $option);
Expand Down Expand Up @@ -558,7 +558,7 @@ private function enumerate_rec_head(
protected function enumerate_final(
int $count,
FencepostCursor $cursor,
StreamTracer $tracer = null,
?StreamTracer $tracer = null,
?EnumerationOptions $option = null
): StreamResult {
StreamBuilder::getDependencyBag()->getLog()
Expand All @@ -580,7 +580,7 @@ protected function enumerate_final_inner(
int $count,
?StreamCursor $cursor,
?int $fencepost_timestamp_ms,
StreamTracer $tracer = null,
?StreamTracer $tracer = null,
?EnumerationOptions $option = null
): StreamResult {
$inner_result = $this->inner->enumerate($count, $cursor, $tracer, $option);
Expand Down Expand Up @@ -608,8 +608,8 @@ protected function enumerate_final_inner(
*/
protected function commit_new_fencepost(
int $current_ms,
int $previous_fencepost_ms = null,
StreamTracer $tracer = null,
?int $previous_fencepost_ms = null,
?StreamTracer $tracer = null,
?EnumerationOptions $option = null
) {
// we are building a new fencepost between $current_ms and $previous_fencepost_ms.
Expand Down Expand Up @@ -659,8 +659,8 @@ protected function enumerate_inner_between(
int $before_ms_inclusive,
?int $after_ms_exclusive,
int $count,
StreamCursor $inner_cursor = null,
StreamTracer $tracer = null
?StreamCursor $inner_cursor = null,
?StreamTracer $tracer = null
): StreamResult {
$option = new EnumerationOptions($before_ms_inclusive, $after_ms_exclusive);
$result = $this->inner->enumerate($count, $inner_cursor, $tracer, $option);
Expand Down Expand Up @@ -701,7 +701,7 @@ public function can_enumerate_with_time_range(): bool
public function log_commit_new_fence_stats(
StreamResult $unranked_candidates,
int $current_ms,
int $previous_fencepost_ms = null
?int $previous_fencepost_ms = null
): void {
$ps_gap_in_seconds = ($current_ms - ($previous_fencepost_ms ?? 0)) / 1000;
// Track when last_ts is missing, putting 1 second as a placeholder
Expand Down
2 changes: 1 addition & 1 deletion lib/Tumblr/StreamBuilder/InjectionAllocatorResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class InjectionAllocatorResult
* @param array|null $state The injector state to coordinate between different pages.
* @throws TypeMismatchException If position is not an int.
*/
public function __construct(array $out, array $state = null)
public function __construct(array $out, ?array $state = null)
{
foreach ($out as $position) {
if (!is_int($position)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function from_template(StreamContext $context): self
/**
* @inheritDoc
*/
public function allocate(int $page_size, array $state = null): InjectionAllocatorResult
public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult
{
$expected_value = $page_size * $this->slot_injection_probability;
$count = floor($expected_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GlobalFixedInjectionAllocator extends FixedInjectionAllocator
/**
* @inheritDoc
*/
public function allocate(int $page_size, array $state = null): InjectionAllocatorResult
public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult
{
$pos_base = $state['pos_base'] ?? 0;
$out = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ abstract class InjectionAllocator extends Templatable
* @param array|null $state The state of the injector.
* @return InjectionAllocatorResult .
*/
abstract public function allocate(int $page_size, array $state = null): InjectionAllocatorResult;
abstract public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LocalFixedInjectionAllocator extends FixedInjectionAllocator
/**
* @inheritDoc
*/
public function allocate(int $page_size, array $state = null): InjectionAllocatorResult
public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult
{
$out = [];
foreach ($this->positions as $p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function from_template(StreamContext $context): self
/**
* @inheritDoc
*/
public function allocate(int $page_size, array $state = null): InjectionAllocatorResult
public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult
{
$out = [];
$mt_randmax = mt_getrandmax();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function from_template(StreamContext $context): self
/**
* @inheritDoc
*/
public function allocate(int $page_size, array $state = null): InjectionAllocatorResult
public function allocate(int $page_size, ?array $state = null): InjectionAllocatorResult
{
$out = [];
// If there's no next_offset is set, we use remainder, most likely in the first page.
Expand Down
2 changes: 1 addition & 1 deletion lib/Tumblr/StreamBuilder/InjectionPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InjectionPlan
* @param array|null $injector_state An array representing the state of the injector, if any, after injection.
* @throws TypeMismatchException If some value in the provided array is not a StreamInjection.
*/
public function __construct(array $index_to_injection, array $injector_state = null)
public function __construct(array $index_to_injection, ?array $injector_state = null)
{
foreach ($index_to_injection as $j) {
if (!($j instanceof StreamInjection)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(array $fetchers, string $identity)
/**
* @inheritDoc
*/
protected function fetch_inner(array $stream_elements, StreamTracer $tracer = null): SignalBundle
protected function fetch_inner(array $stream_elements, ?StreamTracer $tracer = null): SignalBundle
{
$bundles = [];
foreach ($this->fetchers as $fetcher) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Tumblr/StreamBuilder/SignalFetchers/SignalFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class SignalFetcher extends Templatable
* @throws TypeMismatchException If some element is not a StreamElement.
* @throws \Exception If the signal fetcher fails for some other reason.
*/
final public function fetch(array $stream_elements, StreamTracer $tracer = null): SignalBundle
final public function fetch(array $stream_elements, ?StreamTracer $tracer = null): SignalBundle
{
foreach ($stream_elements as $stream_element) {
if (!($stream_element instanceof StreamElement)) {
Expand Down Expand Up @@ -72,7 +72,7 @@ final public function fetch(array $stream_elements, StreamTracer $tracer = null)
* @param StreamTracer|null $tracer Tracer to use for metrics and logging of signal fetching process.
* @return SignalBundle
*/
abstract protected function fetch_inner(array $stream_elements, StreamTracer $tracer = null): SignalBundle;
abstract protected function fetch_inner(array $stream_elements, ?StreamTracer $tracer = null): SignalBundle;

/**
* Get the string representation of the current signal fetcher.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class TimestampFetcher extends SignalFetcher
/**
* @inheritDoc
*/
protected function fetch_inner(array $stream_elements, StreamTracer $tracer = null): SignalBundle
protected function fetch_inner(array $stream_elements, ?StreamTracer $tracer = null): SignalBundle
{
$builder = new SignalBundleBuilder();
foreach ($stream_elements as $stream_element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ConcatenatedStreamCursor extends StreamCursor
* @param StreamCursor $source_cursor The original cursor of element
* @throws \InvalidArgumentException If source index is not an int.
*/
public function __construct(int $source_index, StreamCursor $source_cursor = null)
public function __construct(int $source_index, ?StreamCursor $source_cursor = null)
{
$this->source_index = $source_index;
$this->source_cursor = $source_cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class FilteredStreamCursor extends StreamCursor
* @param StreamCursor|null $cursor The inner cursor tracking pagination state of the inner stream to be filtered.
* @param StreamFilterState|null $filter_state The filter state.
*/
public function __construct(StreamCursor $cursor = null, StreamFilterState $filter_state = null)
public function __construct(?StreamCursor $cursor = null, ?StreamFilterState $filter_state = null)
{
$this->cursor = $cursor;
$this->filter_state = $filter_state;
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function from_template(StreamContext $context): self
* @param StreamFilterState|null $filter_state The filter state.
* @return FilteredStreamCursor
*/
public function with_filter_state(StreamFilterState $filter_state = null): FilteredStreamCursor
public function with_filter_state(?StreamFilterState $filter_state = null): FilteredStreamCursor
{
return new self($this->cursor, $filter_state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class InjectedStreamCursor extends StreamCursor
* @param StreamCursor $inner_cursor The cursor for the inner stream.
* @param array|null $injector_state The injector state.
*/
public function __construct(StreamCursor $inner_cursor = null, array $injector_state = null)
public function __construct(?StreamCursor $inner_cursor = null, ?array $injector_state = null)
{
$this->inner_cursor = $inner_cursor;
$this->injector_state = $injector_state;
Expand Down
4 changes: 2 additions & 2 deletions lib/Tumblr/StreamBuilder/StreamCursors/MultiCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class MultiCursor extends StreamCursor
* @param array $stream_to_cursor Mapping from stream ids (strings) to StreamCursor objects
* @param array|null $injector_state State of injector, if any.
*/
public function __construct(array $stream_to_cursor, array $injector_state = null)
public function __construct(array $stream_to_cursor, ?array $injector_state = null)
{
$this->stream_to_cursor = $stream_to_cursor;
$this->injector_state = $injector_state;
Expand Down Expand Up @@ -115,7 +115,7 @@ public function get_injector_state()
* @param array|null $injector_state State of injector, if any.
* @return MultiCursor
*/
public function with_injector_state(array $injector_state = null): self
public function with_injector_state(?array $injector_state = null): self
{
return new MultiCursor($this->stream_to_cursor, $injector_state);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Tumblr/StreamBuilder/StreamCursors/StreamCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class StreamCursor extends Templatable
* @param StreamCursor|null $other The other cursor.
* @return bool True, iff the cursors can combine.
*/
final public function can_combine_with(StreamCursor $other = null): bool
final public function can_combine_with(?StreamCursor $other = null): bool
{
return is_null($other) || $this->_can_combine_with($other);
}
Expand All @@ -73,7 +73,7 @@ final public function can_combine_with(StreamCursor $other = null): bool
* @throws UncombinableCursorException If the provided cursor cannot be combined
* with this cursor.
*/
final public function combine_with(StreamCursor $other = null): self
final public function combine_with(?StreamCursor $other = null): self
{
if (is_null($other)) {
return $this;
Expand Down Expand Up @@ -158,7 +158,7 @@ public static function encode(
string $secret,
string $encrypt_key,
string $initial_vector_seed = '',
CacheProvider $cache_provider = null,
?CacheProvider $cache_provider = null,
int $cache_size_threshold = self::DEFAULT_CACHE_SIZE_THRESHOLD,
?string $context = null,
?string $current_user_id = null
Expand Down Expand Up @@ -220,7 +220,7 @@ public static function decode(
array $encrypt_keys,
?string $current_user_id = null,
array $encrypt_seeds = [],
CacheProvider $cache_provider = null
?CacheProvider $cache_provider = null
): ?self {
if (empty(trim($cursor_string))) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/Tumblr/StreamBuilder/StreamFilterState.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class StreamFilterState extends Templatable
* @param StreamFilterState|null $other The other state.
* @return bool True, iff the states can merge.
*/
final public function can_merge_with(StreamFilterState $other = null): bool
final public function can_merge_with(?StreamFilterState $other = null): bool
{
return is_null($other) || $this->_can_merge_with($other);
}
Expand All @@ -52,7 +52,7 @@ abstract protected function _can_merge_with(StreamFilterState $other): bool;
* @return StreamFilterState The combined state.
* @throws UnmergeableFilterStateException If the provided state cannot be merged with this state.
*/
final public function merge_with(StreamFilterState $other = null): StreamFilterState
final public function merge_with(?StreamFilterState $other = null): StreamFilterState
{
if (is_null($other)) {
return $this;
Expand Down
Loading
Loading