Skip to content

Conversation

@rennokki
Copy link
Member

@rennokki rennokki commented Dec 29, 2025

This pull request applies code style fixes from an analysis carried out by StyleCI.


For more information, click here.

Summary by Sourcery

Align nullable parameter type hints across the Kubernetes client library with StyleCI recommendations.

Enhancements:

  • Mark optional parameters with explicit nullable types (e.g., ?string, ?Closure, ?array) throughout cluster traits, resource helpers, instances, and exception classes to improve type clarity and static analysis.
  • Update test signatures to reflect nullable context parameters for environment-based kubeconfig loading.

Copilot AI review requested due to automatic review settings December 29, 2025 16:36
@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 29, 2025

Reviewer's Guide

This PR applies StyleCI-driven code style updates by adding explicit nullable type hints (e.g., ?string, ?Closure, ?array) to parameters that already default to null across cluster traits, resource helpers, instance classes, exceptions, and tests, without changing runtime behavior.

Class diagram for updated cluster traits and KubernetesCluster constructor

classDiagram
    class KubernetesCluster {
        +__construct(url: string = null)
    }

    class AuthenticatesCluster {
        +withToken(token: string = null) $this
        +withTokenFromCommandProvider(cmdPath: string, cmdArgs: string = null, tokenPath: string = null) $this
        +loadTokenFromFile(path: string = null) $this
        +httpAuthentication(username: string = null, password: string = null) $this
        +withCertificate(path: string = null) $this
        +withPrivateKey(path: string = null) $this
        +withCaCertificate(path: string = null) $this
    }

    class LoadsFromKubeConfig {
        +fromKubeConfigVariable(context: string = null) KubernetesCluster
        +fromKubeConfigYaml(yaml: string, context: string = null) KubernetesCluster
        +fromKubeConfigYamlFile(path: string = "/.kube/config", context: string = null) KubernetesCluster
        +fromKubeConfigArray(kubeConfigArray: array, context: string = null) KubernetesCluster
        -loadKubeConfigFromArray(kubeconfig: array, context: string = null) void
    }

    class MakesWebsocketCalls {
        -makeWsRequest(path: string, callback: Closure = null, query: array) mixed
    }

    class RunsClusterOperations {
        +exec(command: mixed, container: string = null, query: array) mixed
        +attach(callback: Closure = null, container: string = null, query: array) mixed
        -getApiPathPrefix(withNamespace: bool = true, preNamespaceAction: string = null) string
    }

    KubernetesCluster ..> AuthenticatesCluster : uses
    KubernetesCluster ..> LoadsFromKubeConfig : uses
    KubernetesCluster ..> MakesWebsocketCalls : uses
    KubernetesCluster ..> RunsClusterOperations : uses
Loading

Class diagram for updated K8s core types and exception

classDiagram
    class K8sResource {
        +register(name: string = null) void
        +getUniqueCrdMacro(kind: string = null, defaultVersion: string = null) string
        +toArray(kind: string = null) array
        +toJson(options: mixed = 0, kind: string = null) string
        +toJsonPayload(kind: string = null) string
    }

    class K8sConfigMap {
        +getData(name: string = null) mixed
    }

    class K8s {
        +fromYamlFile(cluster: mixed, path: string, callback: Closure = null) K8sResource
        +fromTemplatedYamlFile(cluster: mixed, path: string, replace: array, callback: Closure = null) K8sResource
        +registerCrd(className: string, name: string = null) void
    }

    class PhpK8sException {
        +__construct(message: mixed = null, code: int = 0, payload: array = null)
    }

    K8sResource <|-- K8sConfigMap
    K8s ..> K8sResource : registers
    K8s ..> K8sConfigMap : creates
    PhpK8sException <|-- Exception
Loading

Class diagram for updated instance helper types

classDiagram
    class Container {
        +setImage(image: string, tag: string = "latest") $this
        +addPort(containerPort: int, protocol: string = "TCP", name: string = null) $this
    }

    class MountedVolume {
        +readOnly() $this
        +mountTo(mountPath: string, subPath: string = null) $this
    }

    class Volume {
        +awsEbs(volumeId: string, fsType: string = "ext4") $this
        +mountTo(mountPath: string, subPath: string = null) MountedVolume
    }

    class Probe {
        +http(path: string = "/healthz", port: int = 8080, headers: array) $this
        +tcp(port: int, host: string = null) $this
    }

    Volume ..> MountedVolume : creates
    MountedVolume ..> Volume : from
    Container ..> Probe : uses for checks
Loading

File-Level Changes

Change Details Files
Add explicit nullable type hints to parameters that already default to null for better static analysis and consistency with modern PHP style.
  • Update cluster authentication and TLS helper methods to use nullable scalar type hints for optional parameters.
  • Update K8sResource serialization and CRD registration helpers to use nullable type hints on optional arguments.
  • Adjust kubeconfig loading helpers and cluster operation methods (exec/attach/API path prefix) to accept nullable parameters explicitly.
  • Update factory/helper methods in K8s facade and KubernetesCluster constructor to use nullable type hints for optional parameters.
  • Align instance helper classes (Container, MountedVolume, Probe, Volume) and K8sConfigMap accessors with nullable parameter type hints.
  • Update PhpK8sException payload parameter to nullable array and fix nullable callback/Closure parameters in websocket helpers and tests.
src/Traits/Cluster/AuthenticatesCluster.php
src/Kinds/K8sResource.php
src/Traits/Cluster/LoadsFromKubeConfig.php
src/Traits/RunsClusterOperations.php
src/K8s.php
src/Exceptions/PhpK8sException.php
src/Instances/Container.php
src/Instances/MountedVolume.php
src/Instances/Probe.php
src/Instances/Volume.php
src/Kinds/K8sConfigMap.php
src/KubernetesCluster.php
src/Traits/Cluster/MakesWebsocketCalls.php
tests/KubeConfigTest.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link

Summary of Changes

Hello @rennokki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aims to improve the overall code quality and maintainability by applying automated style fixes. The core change involves updating function signatures to explicitly declare nullable types for parameters that can accept null, which enhances type safety and leverages modern PHP features. This ensures a more robust and predictable codebase, making it easier for developers to understand and work with the API.

Highlights

  • Code Style Fixes: This pull request applies automated code style fixes across the codebase, primarily focusing on PHP type hinting.
  • Nullable Type Hints: Introduced nullable type declarations (?) for function parameters that have a default null value, aligning with modern PHP standards (PHP 7.1+).
  • Automated Formatting: The changes were automatically generated by StyleCI, ensuring consistent code formatting and adherence to predefined style rules.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly applies nullable type hints to parameters across the codebase, aligning with modern PHP standards and improving type safety. The changes are consistent and well-executed. I've noted a few minor opportunities to update PHPDoc blocks to match the new function signatures for better consistency and clarity. Overall, this is a great improvement.

* @return $this
*/
public function addPort(int $containerPort, string $protocol = 'TCP', string $name = null)
public function addPort(int $containerPort, string $protocol = 'TCP', ?string $name = null)

Choose a reason for hiding this comment

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

medium

While the change to a nullable type ?string for $name is correct, the corresponding PHPDoc on line 24 is now inconsistent. Please consider updating it to @param string|null $name to match the function signature.

* @return $this
*/
public function tcp(int $port, string $host = null)
public function tcp(int $port, ?string $host = null)

Choose a reason for hiding this comment

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

medium

The type hint for $host has been correctly updated to be nullable. To maintain consistency, the PHPDoc for this parameter on line 72 should also be updated to reflect that it can be null. It should be @param string|null $host.

* @return $this
*/
public function withTokenFromCommandProvider(string $cmdPath, string $cmdArgs = null, string $tokenPath = null)
public function withTokenFromCommandProvider(string $cmdPath, ?string $cmdArgs = null, ?string $tokenPath = null)

Choose a reason for hiding this comment

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

medium

The change to nullable types for $cmdArgs and $tokenPath is correct. However, there's a small typo in the PHPDoc for $cmdArgs on line 79. It says @param string|nll $cmdArgs instead of @param string|null $cmdArgs. Please consider fixing this typo for better documentation clarity.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant