Skip to content

Return type inconsistency in retrieveCachedContent(): docblock says string but method may return false #1175

@zigzagdev

Description

@zigzagdev

Summary

In Smarty\Cacheresource\File::retrieveCachedContent(), the docblock indicates that the method returns a string, but the implementation may return false when the cache file does not exist.

/**
 * Read cached template from cache
 *
 * @param Template $_template template object
 *
 * @return string content
 */
public function retrieveCachedContent(Template $_template)
{
    if (is_file($_template->getCached()->filepath)) {
        return file_get_contents($_template->getCached()->filepath);
    }
    return false;
}

This creates a mismatch between the documented return type and the actual return value.

Question

Is the intended contract of this method:

  1. string|false (return cached content or false if not found), or
  2. always string, where missing cache should be handled differently (e.g. exception or empty string)?

Before opening a PR, I would like to confirm the expected behavior.

Possible solutions

Depending on the intended contract:

  • Option A — adjust documentation
    Update the docblock to reflect the actual return type, e.g.
    @return string|false

  • Option B — enforce a string return type
    Ensure the method always returns a string and handle missing cache differently.

Next step

Once the expected behavior is clarified, I’d be happy to open a PR to align either the implementation or the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions