I am facing an issue with a code snippet that sets height based on certain conditions and devices. The error message indicates that the Cyclomatic complexity is too high (28). How can I go about resolving this problem?
function adjustHeightForAttributes() {
var elementHeight = document.getElementById('listSearchOptions');
var childNoLen = $('.attributelistContainer .requestedAttr span').length;
if (childNoLen >= 1) {
$('.attributelistContainer').css({"overflow-y":"auto"});
}
// Media query checks
var widthMinCheck = window.matchMedia("(min-width: 768px)").matches;
var widthMaxCheck = window.matchMedia("(max-width: 1024px)").matches;
var orientationCheck = window.matchMedia("(orientation: landscape)").matches;
var orientationCheckPortrait = window.matchMedia("(orientation: portrait)").matches;
// Boolean value checks
var bothFalse = vm.searchByRoomNo === false && childNoLen === 0;
var bothTrue = vm.searchByRoomNo === true && childNoLen >= 1;
var roomSearchTrue = vm.searchByRoomNo === true && childNoLen === 0;
var childLenTrue = vm.searchByRoomNo === false && childNoLen >= 1;
// Scroll existence check
var scrollExists = $('#listSearchOptions')[0].scrollHeight > $('#listSearchOptions')[0].clientHeight;
if (widthMinCheck && widthMaxCheck && orientationCheck) {
console.log("oreintationCheck.. " + orientationCheck);
// Handling different scenarios based on conditions
if (bothFalse) {
// Code block based on condition
}
if (childLenTrue) {
// Code block based on condition
}
if (bothTrue) {
// Code block based on condition
}
if (roomSearchTrue) {
// Code block based on condition
}
} else if (orientationCheckPortrait) {
// Handle scenarios for portrait orientation
} else {
// Fallback scenario handling
}
}