File AppRegistryController.php
has 288 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2023, ownCloud GmbH
Method buildWebUri
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function buildWebUri(array $app_info, string $fileId): ?string {
$uri = null;
$app_name = $app_info['oc_app_name'];
# https://github.com/ONLYOFFICE/onlyoffice-owncloud/blob/2afca075249f24d857f0b3097d565f5129e88d17/appinfo/routes.php#LL27C47-L27C53
if ($app_name === 'onlyoffice') {
Method new
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function new(?string $parent_container_id, ?string $filename): DataResponse {
$userAgent = $this->request->getHeader('User-Agent') ?? '-';
$this->logger->info("new($parent_container_id, $filename) - $userAgent");
if ($parent_container_id === null) {
Method openWithWeb
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function openWithWeb(?string $file_id, ?string $app_name): DataResponse {
$userAgent = $this->request->getHeader('User-Agent') ?? '-';
$this->logger->info("openWithWeb($file_id, $app_name) - $userAgent");
$fileId = $this->extractFileId($file_id);
$nodes = $this->rootFolder->getById($fileId, true);
Function buildWebUri
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function buildWebUri(array $app_info, string $fileId): ?string {
$uri = null;
$app_name = $app_info['oc_app_name'];
# https://github.com/ONLYOFFICE/onlyoffice-owncloud/blob/2afca075249f24d857f0b3097d565f5129e88d17/appinfo/routes.php#LL27C47-L27C53
if ($app_name === 'onlyoffice') {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function list
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function list(): array {
$mimeTypes = [];
foreach (self::$apps as $app_name => $app_info) {
if ($this->appManager->isEnabledForUser($app_info['oc_app_name'])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
$appName,
IRequest $request,
IAppManager $appManager,
IRootFolder $rootFolder,
IURLGenerator $generator,
Function openWithWeb
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function openWithWeb(?string $file_id, ?string $app_name): DataResponse {
$userAgent = $this->request->getHeader('User-Agent') ?? '-';
$this->logger->info("openWithWeb($file_id, $app_name) - $userAgent");
$fileId = $this->extractFileId($file_id);
$nodes = $this->rootFolder->getById($fileId, true);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return new DataResponse([
'file_id' => (string)$newFile->getId()]);
Avoid too many return
statements within this method. Open
return new DataResponse([
'uri' => $uri]);
Avoid too many return
statements within this method. Open
return new DataResponse([
"code" => "INVALID_PARAMETER",
"message" => "the file already exists"
], 403);
Avoid too many return
statements within this method. Open
return new DataResponse([
"code" => "INVALID_PARAMETER",
"message" => $e->getMessage()
], 400);
Function new
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function new(?string $parent_container_id, ?string $filename): DataResponse {
$userAgent = $this->request->getHeader('User-Agent') ?? '-';
$this->logger->info("new($parent_container_id, $filename) - $userAgent");
if ($parent_container_id === null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getDefaultApp
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getDefaultApp(string $mimeType): ?string {
# get mime from file and see which of the enabled apps matches
foreach (self::$apps as $app_name => $app_info) {
$oc_app_name = $app_info['oc_app_name'];
if ($this->appManager->isEnabledForUser($oc_app_name)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 4 locations. Consider refactoring. Open
public function __construct(
$appName,
IRequest $request,
IAppManager $appManager,
IRootFolder $rootFolder,
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 108.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76