Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes Non-static method #34

Merged
merged 2 commits into from
Oct 17, 2024
Merged

fixes Non-static method #34

merged 2 commits into from
Oct 17, 2024

Conversation

skerbis
Copy link
Member

@skerbis skerbis commented Oct 17, 2024

Non-static method FriendsOfRedaxo\VidStack\Video::getVideoInfo() cannot be called statically

Summary by CodeRabbit

  • New Features

    • Enhanced video information retrieval through a streamlined static method.
    • Added new methods for improved video player functionality, including support for OEmbed tags.
    • Expanded support for audio files within the video class.
    • Introduced consent management for embedding videos from platforms like YouTube and Vimeo.
  • Documentation

    • Updated README with detailed installation instructions and usage examples.
    • Clarified constructor parameters and added descriptions for new methods.
  • Bug Fixes

    • Corrected method calls to ensure accurate source string usage.
  • Refactor

    • Reorganized subtitle generation for better HTML structure.

Non-static method FriendsOfRedaxo\VidStack\Video::getVideoInfo() cannot be called statically
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve significant modifications to the Video class in the lib/video.php file. The getVideoInfo method has been changed from a private instance method to a private static method, requiring a string $source parameter. All internal calls to this method have been updated accordingly. Additionally, the generateFull and generate methods now utilize the static version of getVideoInfo. The handling of subtitles within the generate method has also been reorganized, affecting the structure of the generated HTML output. The README.md file has been enhanced with new content, installation guides, usage examples, and a flowchart.

Changes

File Change Summary
lib/video.php - Changed getVideoInfo from private instance method to private static method with string $source parameter.
- Updated all calls to getVideoInfo to pass the source string.
- Modified generateFull and generate methods to call the new static getVideoInfo.
- Reorganized subtitle handling in generate method, moving code inside the <media-provider> tag.
- Added methods: parseOembedTags(string $content): string and videoOembedHelper(): void.
- Clarified constructor and method documentation.
README.md - Added detailed installation guide and usage examples for the Vidstack PHP class.
- Expanded sections on constructor parameters and new methods.
- Introduced consent management section for embedding videos.
- Included flowchart illustrating the Video class process.

Poem

🐇 In the land of code where videos play,
A static method joins the fray.
With strings to guide, it finds the light,
Subtitles dance in HTML's sight.
Hooray for changes, let’s all cheer,
For clearer paths, we hold so dear! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
lib/video.php (3)

Line range hint 173-199: Consider caching getVideoInfo results for efficiency

Since getVideoInfo is called multiple times with the same $source, consider caching its result in an instance variable to avoid redundant processing, especially if the method's complexity increases in the future.

You can implement caching as follows:

 class Video
 {
     private readonly string $source;
+    private ?array $videoInfo = null;

     // ...

     public function generateFull(): string
     {
-        $videoInfo = self::getVideoInfo($this->source);
+        $videoInfo = $this->getVideoInfoCached();
         $isAudio = self::isAudio($this->source);
         // ...
     }

     public function generate(): string
     {
         // ...
-        $videoInfo = self::getVideoInfo($this->source);
+        $videoInfo = $this->getVideoInfoCached();
         // ...
     }

+    private function getVideoInfoCached(): array
+    {
+        if ($this->videoInfo === null) {
+            $this->videoInfo = self::getVideoInfo($this->source);
+        }
+        return $this->videoInfo;
+    }
 }

This approach enhances performance by ensuring getVideoInfo is called only once per instance.


Line range hint 44-47: Handle missing translation keys gracefully

In the getText method, if a translation key is missing, the method returns "[[$key]]". While this indicates a missing translation, it might not be user-friendly. Consider providing a default message or logging the missing keys for easier debugging.

You could modify the method as follows:

-    return self::$translations[$this->lang][$key] ?? "[[{$key}]]";
+    return self::$translations[$this->lang][$key] ?? '';

Alternatively, log the missing keys:

if (!isset(self::$translations[$this->lang][$key])) {
    // Log the missing translation key
    error_log("Missing translation for key '{$key}' in language '{$this->lang}'");
}
return self::$translations[$this->lang][$key] ?? '';

Line range hint 18-23: Avoid exposing file paths in exception messages

In loadTranslations, the exception message reveals the file path when the translations file is not found. Exposing file paths can be a security risk. Consider modifying the exception message to avoid disclosing sensitive information.

Update the exception message as follows:

-    throw new \RuntimeException("Translations file not found: $file");
+    throw new \RuntimeException("Translations file not found.");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ef0c099 and b85e6ab.

📒 Files selected for processing (1)
  • lib/video.php (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
lib/video.php (6)

141-149: Appropriate refactoring of getVideoInfo to a static method

Changing getVideoInfo to a static method with the string $source parameter is a suitable fix for the issue where a non-static method was being called statically. This refactoring enhances the method's reusability and ensures that it no longer depends on instance properties.


208-209: Confirm update of getVideoInfo call in generate method

In the generate method, the call to getVideoInfo has been correctly updated to self::getVideoInfo($this->source), aligning with the new static method signature. This change ensures consistency across the class methods.


Line range hint 208-221: Confirm that subtitles are correctly nested within <media-provider>

The subtitles are now moved inside the <media-provider> tag in the generate method. Ensure that this change conforms to the expected HTML structure and that subtitle functionality remains unaffected in the media player.

Testing the media player with subtitles will help confirm that they display correctly after this structural change.


Line range hint 173-199: Verify consent placeholder functionality for external platforms

In generateFull, the consent placeholder is generated for videos from external platforms like YouTube or Vimeo. Ensure that the consent mechanism works as intended and that the user experience is smooth when loading external content.

Consider testing with actual YouTube and Vimeo videos to confirm the consent process and video playback.


148-149: Verify the Vimeo URL pattern matches all formats

The regular expression for Vimeo URLs in getVideoInfo may not cover all possible Vimeo URL formats. Ensure that the pattern accurately captures video IDs from various Vimeo URL structures, including those with additional path segments or query parameters.

You can test the regex pattern with different Vimeo URLs using the following script:

#!/bin/bash
# Description: Test the Vimeo regex pattern with various Vimeo URLs.

# Expected: The pattern should match and extract the video ID from each URL.

# Sample Vimeo URLs to test
urls=(
  "https://vimeo.com/123456789"
  "https://player.vimeo.com/video/123456789"
  "https://vimeo.com/channels/staffpicks/123456789"
  "https://vimeo.com/album/1234567/video/123456789"
  "https://vimeo.com/groups/name/videos/123456789"
)

pattern='~(?:<iframe [^>]*src=")?(?:https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/(progressive_redirect\/playback|external|videos?))?\/([0-9]+)[^\s]*)"?(?:[^>]*><\/iframe>)?(?:<p>.*<\/p>)?~ix'

for url in "${urls[@]}"; do
  if [[ $url =~ $pattern ]]; then
    echo "Matched URL: $url"
    echo "Extracted Video ID: ${BASH_REMATCH[2]}"
    echo
  else
    echo "No match for URL: $url"
    echo
  fi
done

173-176: Ensure all calls to getVideoInfo are updated

In the generateFull method, the call to getVideoInfo has been correctly updated to self::getVideoInfo($this->source). Verify that all other calls to getVideoInfo within the class have been updated to match the new static method signature.

You can run the following script to confirm that all calls to getVideoInfo pass the $source parameter:

@skerbis skerbis merged commit 24a155a into main Oct 17, 2024
1 check was pending
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